Changes in uspace/lib/congfx/src/console.c [211fd68:7470d97] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/congfx/src/console.c
r211fd68 r7470d97 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 57 57 static errno_t console_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 58 58 static errno_t console_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 59 static errno_t console_gc_cursor_get_pos(void *, gfx_coord2_t *);60 static errno_t console_gc_cursor_set_pos(void *, gfx_coord2_t *);61 static errno_t console_gc_cursor_set_visible(void *, bool);62 59 63 60 gfx_context_ops_t console_gc_ops = { … … 69 66 .bitmap_destroy = console_gc_bitmap_destroy, 70 67 .bitmap_render = console_gc_bitmap_render, 71 .bitmap_get_alloc = console_gc_bitmap_get_alloc, 72 .cursor_get_pos = console_gc_cursor_get_pos, 73 .cursor_set_pos = console_gc_cursor_set_pos, 74 .cursor_set_visible = console_gc_cursor_set_visible 68 .bitmap_get_alloc = console_gc_bitmap_get_alloc 75 69 }; 76 77 /** Convert pixel value to charfield.78 *79 * On the bottom of this function lies a big big hack. In the absence80 * of support for different color formats (FIX ME!), here's a single81 * format that can represent both 3x8bit RGB and 24-bit characters82 * with 8-bit EGA attributes (i.e. we can specify the foreground and83 * background colors individually).84 *85 * A R G B86 * 0 red grn blu 24-bit color87 * attr c2 c1 c0 attribute + 24-bit character88 */89 static void console_gc_pix_to_charfield(pixel_t clr, charfield_t *ch)90 {91 uint8_t attr;92 93 if ((clr >> 24) == 0xff) {94 /* RGB (no text) */95 ch->ch = 0;96 ch->flags = CHAR_FLAG_DIRTY;97 ch->attrs.type = CHAR_ATTR_RGB;98 ch->attrs.val.rgb.fgcolor = clr;99 ch->attrs.val.rgb.bgcolor = clr;100 } else {101 /* EGA attributes (with text) */102 attr = clr >> 24;103 ch->ch = clr & 0xffffff;104 ch->flags = CHAR_FLAG_DIRTY;105 ch->attrs.type = CHAR_ATTR_INDEX;106 ch->attrs.val.index.fgcolor = attr & 0x7;107 ch->attrs.val.index.bgcolor = (attr >> 4) & 0x7;108 ch->attrs.val.index.attr =109 ((attr & 0x8) ? CATTR_BRIGHT : 0) +110 ((attr & 0x80) ? CATTR_BLINK : 0);111 }112 }113 70 114 71 /** Set clipping rectangle on console GC. … … 144 101 console_gc_t *cgc = (console_gc_t *) arg; 145 102 146 cgc->clr = PIXEL( color->attr, color->r >> 8, color->g >> 8, color->b >> 8);103 cgc->clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8); 147 104 return EOK; 148 105 } … … 168 125 cols = cgc->rect.p1.x - cgc->rect.p0.x; 169 126 170 console_gc_pix_to_charfield(cgc->clr, &ch); 127 ch.ch = cgc->clr >> 24; 128 ch.flags = CHAR_FLAG_DIRTY; 129 ch.attrs.type = CHAR_ATTR_RGB; 130 ch.attrs.val.rgb.fgcolor = cgc->clr ^ 0xffffff; 131 ch.attrs.val.rgb.bgcolor = cgc->clr; 171 132 172 133 for (y = crect.p0.y; y < crect.p1.y; y++) { … … 278 239 279 240 free(cgc); 280 return EOK;281 }282 283 /** Free up console for other users, suspending GC operation.284 *285 * @param cgc Console GC286 * @return EOK on success or an error code287 */288 errno_t console_gc_suspend(console_gc_t *cgc)289 {290 console_unmap(cgc->con, cgc->buf);291 cgc->buf = NULL;292 293 console_clear(cgc->con);294 console_cursor_visibility(cgc->con, true);295 return EOK;296 }297 298 /** Resume GC operation after suspend.299 *300 * @param cgc Console GC301 * @return EOK on success or an error code302 */303 errno_t console_gc_resume(console_gc_t *cgc)304 {305 errno_t rc;306 307 console_clear(cgc->con);308 309 rc = console_map(cgc->con, cgc->rect.p1.x, cgc->rect.p1.y, &cgc->buf);310 if (rc != EOK)311 return rc;312 313 241 return EOK; 314 242 } … … 440 368 y - offs.y - cbm->rect.p0.y); 441 369 442 console_gc_pix_to_charfield(clr, &ch); 370 ch.ch = clr >> 24; 371 ch.flags = CHAR_FLAG_DIRTY; 372 ch.attrs.type = CHAR_ATTR_RGB; 373 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 374 ch.attrs.val.rgb.bgcolor = clr; 375 443 376 cbm->cgc->buf[y * cols + x] = ch; 444 377 } … … 453 386 y - offs.y - cbm->rect.p0.y); 454 387 455 console_gc_pix_to_charfield(clr, &ch); 388 ch.ch = clr >> 24; 389 ch.flags = CHAR_FLAG_DIRTY; 390 ch.attrs.type = CHAR_ATTR_RGB; 391 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 392 ch.attrs.val.rgb.bgcolor = clr; 456 393 457 394 if (clr != cbm->key_color) … … 461 398 } else { 462 399 /* Color key & colorize */ 463 console_gc_pix_to_charfield(cbm->cgc->clr, &ch); 400 ch.ch = 0; 401 ch.flags = CHAR_FLAG_DIRTY; 402 ch.attrs.type = CHAR_ATTR_RGB; 403 ch.attrs.val.rgb.fgcolor = cbm->cgc->clr; 404 ch.attrs.val.rgb.bgcolor = cbm->cgc->clr; 464 405 465 406 for (y = crect.p0.y; y < crect.p1.y; y++) { … … 494 435 } 495 436 496 /** Get cursor position on console GC.497 *498 * @param arg Console GC499 * @param pos Place to store position500 *501 * @return EOK on success or an error code502 */503 static errno_t console_gc_cursor_get_pos(void *arg, gfx_coord2_t *pos)504 {505 console_gc_t *cgc = (console_gc_t *) arg;506 sysarg_t col;507 sysarg_t row;508 errno_t rc;509 510 rc = console_get_pos(cgc->con, &col, &row);511 if (rc != EOK)512 return rc;513 514 pos->x = col;515 pos->y = row;516 return EOK;517 }518 519 /** Set cursor position on console GC.520 *521 * @param arg Console GC522 * @param pos New cursor position523 *524 * @return EOK on success or an error code525 */526 static errno_t console_gc_cursor_set_pos(void *arg, gfx_coord2_t *pos)527 {528 console_gc_t *cgc = (console_gc_t *) arg;529 530 console_set_pos(cgc->con, pos->x, pos->y);531 return EOK;532 }533 534 /** Set cursor visibility on console GC.535 *536 * @param arg Console GC537 * @param visible @c true iff cursor should be made visible538 *539 * @return EOK on success or an error code540 */541 static errno_t console_gc_cursor_set_visible(void *arg, bool visible)542 {543 console_gc_t *cgc = (console_gc_t *) arg;544 545 console_cursor_visibility(cgc->con, visible);546 return EOK;547 }548 549 437 /** @} 550 438 */
Note:
See TracChangeset
for help on using the changeset viewer.