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