Changeset 8a9a41e in mainline for uspace/lib/congfx/src/console.c


Ignore:
Timestamp:
2021-10-24T08:28:43Z (2 years ago)
Author:
GitHub <noreply@…>
Children:
f628215
Parents:
2ce943a (diff), cd981f2a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Erik Kučák <35500848+Riko196@…> (2021-10-24 08:28:43)
git-committer:
GitHub <noreply@…> (2021-10-24 08:28:43)
Message:

Merge branch 'HelenOS:master' into master

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/congfx/src/console.c

    r2ce943a r8a9a41e  
    5757static errno_t console_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
    5858static errno_t console_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     59static errno_t console_gc_cursor_get_pos(void *, gfx_coord2_t *);
     60static errno_t console_gc_cursor_set_pos(void *, gfx_coord2_t *);
     61static errno_t console_gc_cursor_set_visible(void *, bool);
    5962
    6063gfx_context_ops_t console_gc_ops = {
     
    6669        .bitmap_destroy = console_gc_bitmap_destroy,
    6770        .bitmap_render = console_gc_bitmap_render,
    68         .bitmap_get_alloc = console_gc_bitmap_get_alloc
     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
    6975};
     76
     77/** Convert pixel value to charfield.
     78 *
     79 * On the bottom of this function lies a big big hack. In the absence
     80 * of support for different color formats (FIX ME!), here's a single
     81 * format that can represent both 3x8bit RGB and 24-bit characters
     82 * with 8-bit EGA attributes (i.e. we can specify the foreground and
     83 * background colors individually).
     84 *
     85 * A    R   G   B
     86 * 0    red grn blu  24-bit color
     87 * attr c2  c1  c0   attribute + 24-bit character
     88 */
     89static void console_gc_pix_to_charfield(pixel_t clr, charfield_t *ch)
     90{
     91        uint8_t attr;
     92
     93        if ((clr >> 24) == 0) {
     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 ^ 0xffffff;
     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}
    70113
    71114/** Set clipping rectangle on console GC.
     
    101144        console_gc_t *cgc = (console_gc_t *) arg;
    102145
    103         cgc->clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8);
     146        cgc->clr = PIXEL(color->attr, color->r >> 8, color->g >> 8, color->b >> 8);
    104147        return EOK;
    105148}
     
    125168        cols = cgc->rect.p1.x - cgc->rect.p0.x;
    126169
    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;
     170        console_gc_pix_to_charfield(cgc->clr, &ch);
    132171
    133172        for (y = crect.p0.y; y < crect.p1.y; y++) {
     
    368407                                    y - offs.y - cbm->rect.p0.y);
    369408
    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 
     409                                console_gc_pix_to_charfield(clr, &ch);
    376410                                cbm->cgc->buf[y * cols + x] = ch;
    377411                        }
     
    386420                                    y - offs.y - cbm->rect.p0.y);
    387421
    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;
     422                                console_gc_pix_to_charfield(clr, &ch);
    393423
    394424                                if (clr != cbm->key_color)
     
    398428        } else {
    399429                /* Color key & colorize */
    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;
     430                console_gc_pix_to_charfield(cbm->cgc->clr, &ch);
    405431
    406432                for (y = crect.p0.y; y < crect.p1.y; y++) {
     
    435461}
    436462
     463/** Get cursor position on console GC.
     464 *
     465 * @param arg Console GC
     466 * @param pos Place to store position
     467 *
     468 * @return EOK on success or an error code
     469 */
     470static errno_t console_gc_cursor_get_pos(void *arg, gfx_coord2_t *pos)
     471{
     472        console_gc_t *cgc = (console_gc_t *) arg;
     473        sysarg_t col;
     474        sysarg_t row;
     475        errno_t rc;
     476
     477        rc = console_get_pos(cgc->con, &col, &row);
     478        if (rc != EOK)
     479                return rc;
     480
     481        pos->x = col;
     482        pos->y = row;
     483        return EOK;
     484}
     485
     486/** Set cursor position on console GC.
     487 *
     488 * @param arg Console GC
     489 * @param pos New cursor position
     490 *
     491 * @return EOK on success or an error code
     492 */
     493static errno_t console_gc_cursor_set_pos(void *arg, gfx_coord2_t *pos)
     494{
     495        console_gc_t *cgc = (console_gc_t *) arg;
     496
     497        console_set_pos(cgc->con, pos->x, pos->y);
     498        return EOK;
     499}
     500
     501/** Set cursor visibility on console GC.
     502 *
     503 * @param arg Console GC
     504 * @param visible @c true iff cursor should be made visible
     505 *
     506 * @return EOK on success or an error code
     507 */
     508static errno_t console_gc_cursor_set_visible(void *arg, bool visible)
     509{
     510        console_gc_t *cgc = (console_gc_t *) arg;
     511
     512        console_cursor_visibility(cgc->con, visible);
     513        return EOK;
     514}
     515
    437516/** @}
    438517 */
Note: See TracChangeset for help on using the changeset viewer.