Ignore:
File:
1 edited

Legend:

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

    ra4e4e29 rbb14312  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7575};
    7676
    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  */
    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 
    11477/** Set clipping rectangle on console GC.
    11578 *
     
    144107        console_gc_t *cgc = (console_gc_t *) arg;
    145108
    146         cgc->clr = PIXEL(color->attr, color->r >> 8, color->g >> 8, color->b >> 8);
     109        cgc->clr = PIXEL(0, color->r >> 8, color->g >> 8, color->b >> 8);
    147110        return EOK;
    148111}
     
    168131        cols = cgc->rect.p1.x - cgc->rect.p0.x;
    169132
    170         console_gc_pix_to_charfield(cgc->clr, &ch);
     133        ch.ch = cgc->clr >> 24;
     134        ch.flags = CHAR_FLAG_DIRTY;
     135        ch.attrs.type = CHAR_ATTR_RGB;
     136        ch.attrs.val.rgb.fgcolor = cgc->clr ^ 0xffffff;
     137        ch.attrs.val.rgb.bgcolor = cgc->clr;
    171138
    172139        for (y = crect.p0.y; y < crect.p1.y; y++) {
     
    280247        return EOK;
    281248}
    282 
    283 /** Free up console for other users, suspending GC operation.
    284  *
    285  * @param cgc Console GC
    286  * @return EOK on success or an error code
    287  */
    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 GC
    301  * @return EOK on success or an error code
    302  */
    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         return EOK;
    314 }
    315 
    316 /** Update console GC size after console resize.
    317  *
    318  * @param con Console object
    319  *
    320  * @return EOK on success or an error code
    321  */
    322 errno_t console_gc_resize(console_gc_t *cgc)
    323 {
    324         sysarg_t rows;
    325         sysarg_t cols;
    326         charfield_t *buf = NULL;
    327         errno_t rc;
    328 
    329         console_unmap(cgc->con, cgc->buf);
    330         cgc->buf = NULL;
    331 
    332         rc = console_get_size(cgc->con, &cols, &rows);
    333         if (rc != EOK)
    334                 goto error;
    335 
    336         rc = console_map(cgc->con, cols, rows, &buf);
    337         if (rc != EOK)
    338                 goto error;
    339 
    340         cgc->rect.p0.x = 0;
    341         cgc->rect.p0.y = 0;
    342         cgc->rect.p1.x = cols;
    343         cgc->rect.p1.y = rows;
    344         cgc->clip_rect = cgc->rect;
    345         cgc->buf = buf;
    346         return EOK;
    347 error:
    348         return rc;
    349 }
    350 
    351249
    352250/** Get generic graphic context from console GC.
     
    476374                                    y - offs.y - cbm->rect.p0.y);
    477375
    478                                 console_gc_pix_to_charfield(clr, &ch);
     376                                ch.ch = clr >> 24;
     377                                ch.flags = CHAR_FLAG_DIRTY;
     378                                ch.attrs.type = CHAR_ATTR_RGB;
     379                                ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff;
     380                                ch.attrs.val.rgb.bgcolor = clr;
     381
    479382                                cbm->cgc->buf[y * cols + x] = ch;
    480383                        }
     
    489392                                    y - offs.y - cbm->rect.p0.y);
    490393
    491                                 console_gc_pix_to_charfield(clr, &ch);
     394                                ch.ch = clr >> 24;
     395                                ch.flags = CHAR_FLAG_DIRTY;
     396                                ch.attrs.type = CHAR_ATTR_RGB;
     397                                ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff;
     398                                ch.attrs.val.rgb.bgcolor = clr;
    492399
    493400                                if (clr != cbm->key_color)
     
    497404        } else {
    498405                /* Color key & colorize */
    499                 console_gc_pix_to_charfield(cbm->cgc->clr, &ch);
     406                ch.ch = 0;
     407                ch.flags = CHAR_FLAG_DIRTY;
     408                ch.attrs.type = CHAR_ATTR_RGB;
     409                ch.attrs.val.rgb.fgcolor = cbm->cgc->clr;
     410                ch.attrs.val.rgb.bgcolor = cbm->cgc->clr;
    500411
    501412                for (y = crect.p0.y; y < crect.p1.y; y++) {
Note: See TracChangeset for help on using the changeset viewer.