Changeset bc52b5b in mainline


Ignore:
Timestamp:
2021-08-15T10:02:32Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
99589a9
Parents:
de0c55a
Message:

Allow the use of EGA attributes/24-bit characters alongside RGB

In a big hack (since we cannot have different pixel formats yet) we
use a pixel format that allows both 24-bit RGB (without character)
or 24-bit character with 8-bit attributes. Thus in GFX we cannot
currently have characters with any RGB color, but we can set
foreground and background individually (and it even works in EGA mode).

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/gfxdemo/gfxdemo.c

    rde0c55a rbc52b5b  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7373static gfx_coord_t vpad;
    7474
     75/** Determine if we are running in text mode.
     76 *
     77 * @param w Screen width
     78 * @param h Screen height
     79 * @return @c true iff we are running in text mode
     80 */
     81static bool demo_is_text(gfx_coord_t w, gfx_coord_t h)
     82{
     83        // XXX Need a proper way to determine text mode
     84        return w <= 80;
     85}
     86
    7587/** Clear screen.
    7688 *
     
    215227
    216228        if (font != NULL) {
    217                 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
    218                 if (rc != EOK)
    219                         goto error;
     229                if (demo_is_text(w, h)) {
     230                        rc = gfx_color_new_ega(0x1e, &color);
     231                        if (rc != EOK)
     232                                goto error;
     233                } else {
     234                        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     235                        if (rc != EOK)
     236                                goto error;
     237                }
    220238
    221239                gfx_text_fmt_init(&fmt);
     
    740758
    741759        for (i = 0; i < 8; i++) {
    742                 rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0,
    743                     (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color);
    744                 if (rc != EOK)
    745                         goto error;
     760                if (demo_is_text(w, h)) {
     761                        rc = gfx_color_new_ega(i, &color);
     762                        if (rc != EOK)
     763                                goto error;
     764                } else {
     765                        rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0,
     766                            (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color);
     767                        if (rc != EOK)
     768                                goto error;
     769                }
    746770
    747771                fmt.color = color;
  • uspace/lib/congfx/src/console.c

    rde0c55a rbc52b5b  
    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 */
     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}
     113
    77114/** Set clipping rectangle on console GC.
    78115 *
     
    107144        console_gc_t *cgc = (console_gc_t *) arg;
    108145
    109         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);
    110147        return EOK;
    111148}
     
    131168        cols = cgc->rect.p1.x - cgc->rect.p0.x;
    132169
    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;
     170        console_gc_pix_to_charfield(cgc->clr, &ch);
    138171
    139172        for (y = crect.p0.y; y < crect.p1.y; y++) {
     
    374407                                    y - offs.y - cbm->rect.p0.y);
    375408
    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 
     409                                console_gc_pix_to_charfield(clr, &ch);
    382410                                cbm->cgc->buf[y * cols + x] = ch;
    383411                        }
     
    392420                                    y - offs.y - cbm->rect.p0.y);
    393421
    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;
     422                                console_gc_pix_to_charfield(clr, &ch);
    399423
    400424                                if (clr != cbm->key_color)
     
    404428        } else {
    405429                /* Color key & colorize */
    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;
     430                console_gc_pix_to_charfield(cbm->cgc->clr, &ch);
    411431
    412432                for (y = crect.p0.y; y < crect.p1.y; y++) {
  • uspace/lib/gfx/include/gfx/color.h

    rde0c55a rbc52b5b  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343extern errno_t gfx_color_new_rgb_i16(uint16_t, uint16_t,
    4444    uint16_t, gfx_color_t **);
     45extern errno_t gfx_color_new_ega(uint8_t, gfx_color_t **);
    4546extern void gfx_color_delete(gfx_color_t *);
    4647extern void gfx_color_get_rgb_i16(gfx_color_t *, uint16_t *, uint16_t *,
    4748    uint16_t *);
     49extern void gfx_color_get_ega(gfx_color_t *, uint8_t *);
    4850
    4951#endif
  • uspace/lib/gfx/private/color.h

    rde0c55a rbc52b5b  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4848        uint16_t g;
    4949        uint16_t b;
     50        uint8_t attr;
    5051};
    5152
  • uspace/lib/gfx/src/color.c

    rde0c55a rbc52b5b  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6969}
    7070
     71/** Create new EGA color.
     72 *
     73 * @param attr EGA attributes
     74 * @param rcolor Place to store pointer to new color
     75 *
     76 * @return EOK on success or an error code, ENOMEM if out of resources,
     77 *         EIO if the graphic device connection was lost
     78 */
     79errno_t gfx_color_new_ega(uint8_t attr, gfx_color_t **rcolor)
     80{
     81        gfx_color_t *color;
     82
     83        color = calloc(1, sizeof(gfx_color_t));
     84        if (color == NULL)
     85                return ENOMEM;
     86
     87        color->attr = attr;
     88
     89        *rcolor = color;
     90        return EOK;
     91}
     92
    7193/** Delete color.
    7294 *
     
    93115}
    94116
     117/** Convert color to EGA attributes.
     118 *
     119 * @param color Color
     120 * @param attr Place to store EGA attributes
     121 */
     122void gfx_color_get_ega(gfx_color_t *color, uint8_t *attr)
     123{
     124        *attr = color->attr;
     125}
     126
    95127/** @}
    96128 */
  • uspace/lib/gfxfont/src/text.c

    rde0c55a rbc52b5b  
    110110        gfx_bitmap_t *bitmap;
    111111        gfx_bitmap_alloc_t alloc;
    112         uint16_t r, g, b;
     112        uint8_t attr;
    113113        pixelmap_t pmap;
    114114        gfx_coord_t x;
    115115        pixel_t pixel;
     116        char32_t c;
     117        size_t off;
    116118        errno_t rc;
    117119
     
    121123         */
    122124
    123         gfx_color_get_rgb_i16(color, &r, &g, &b);
    124 
    125         /*
    126          * We are setting the *background* color, the foreground color
    127          * will be set to its complement.
    128          */
    129         r = 0xff ^ (r >> 8);
    130         g = 0xff ^ (g >> 8);
    131         b = 0xff ^ (b >> 8);
     125        gfx_color_get_ega(color, &attr);
    132126
    133127        gfx_bitmap_params_init(&params);
     
    156150        pmap.data = alloc.pixels;
    157151
     152        off = 0;
    158153        for (x = 0; x < params.rect.p1.x; x++) {
    159                 pixel = PIXEL(str[x], r, g, b);
     154                c = str_decode(str, &off, STR_NO_LIMIT);
     155                pixel = PIXEL(attr,
     156                    (c >> 16) & 0xff,
     157                    (c >> 8) & 0xff,
     158                    c & 0xff);
    160159                pixelmap_put_pixel(&pmap, x, 0, pixel);
    161160        }
  • uspace/lib/memgfx/src/memgc.c

    rde0c55a rbc52b5b  
    108108        mem_gc_t *mgc = (mem_gc_t *) arg;
    109109        uint16_t r, g, b;
     110        uint8_t attr;
    110111
    111112        gfx_color_get_rgb_i16(color, &r, &g, &b);
    112         mgc->color = PIXEL(0, r >> 8, g >> 8, b >> 8);
     113        gfx_color_get_ega(color, &attr);
     114        mgc->color = PIXEL(attr, r >> 8, g >> 8, b >> 8);
    113115        return EOK;
    114116}
  • uspace/lib/ui/src/pbutton.c

    rde0c55a rbc52b5b  
    366366        rect.p1.y = pbutton->rect.p0.y + 1;
    367367
    368         rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_highlight_color);
     368        rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_face_color);
    369369        if (rc != EOK)
    370370                goto error;
  • uspace/lib/ui/src/resource.c

    rde0c55a rbc52b5b  
    4747static const char *ui_typeface_path = "/data/font/helena.tpf";
    4848
    49 /** Create new UI resource.
     49/** Create new UI resource in graphics mode.
    5050 *
    5151 * @param gc Graphic context
    52  * @param textmode @c true if running in text mode
    5352 * @param rresource Place to store pointer to new UI resource
    5453 * @return EOK on success, ENOMEM if out of memory
    5554 */
    56 errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
     55static errno_t ui_resource_create_gfx(gfx_context_t *gc,
    5756    ui_resource_t **rresource)
    5857{
     
    8786                return ENOMEM;
    8887
    89         if (textmode) {
    90                 /* Create dummy font for text mode */
    91                 rc = gfx_typeface_create(gc, &tface);
    92                 if (rc != EOK)
    93                         goto error;
    94 
    95                 rc = gfx_font_create_textmode(tface, &font);
    96                 if (rc != EOK)
    97                         goto error;
    98         } else {
    99                 rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
    100                 if (rc != EOK)
    101                         goto error;
    102 
    103                 finfo = gfx_typeface_first_font(tface);
    104                 if (finfo == NULL) {
    105                         rc = EIO;
    106                         goto error;
    107                 }
    108 
    109                 rc = gfx_font_open(finfo, &font);
    110                 if (rc != EOK)
    111                         goto error;
     88        rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
     89        if (rc != EOK)
     90                goto error;
     91
     92        finfo = gfx_typeface_first_font(tface);
     93        if (finfo == NULL) {
     94                rc = EIO;
     95                goto error;
    11296        }
     97
     98        rc = gfx_font_open(finfo, &font);
     99        if (rc != EOK)
     100                goto error;
    113101
    114102        rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color);
     
    201189        resource->tface = tface;
    202190        resource->font = font;
    203         resource->textmode = textmode;
     191        resource->textmode = false;
    204192
    205193        resource->btn_frame_color = btn_frame_color;
     
    280268}
    281269
     270/** Create new UI resource in text mode.
     271 *
     272 * @param gc Graphic context
     273 * @param rresource Place to store pointer to new UI resource
     274 * @return EOK on success, ENOMEM if out of memory
     275 */
     276static errno_t ui_resource_create_text(gfx_context_t *gc,
     277    ui_resource_t **rresource)
     278{
     279        ui_resource_t *resource;
     280        gfx_typeface_t *tface = NULL;
     281        gfx_font_t *font = NULL;
     282        gfx_color_t *btn_frame_color = NULL;
     283        gfx_color_t *btn_face_color = NULL;
     284        gfx_color_t *btn_text_color = NULL;
     285        gfx_color_t *btn_highlight_color = NULL;
     286        gfx_color_t *btn_shadow_color = NULL;
     287        gfx_color_t *wnd_face_color = NULL;
     288        gfx_color_t *wnd_text_color = NULL;
     289        gfx_color_t *wnd_sel_text_color = NULL;
     290        gfx_color_t *wnd_sel_text_bg_color = NULL;
     291        gfx_color_t *wnd_frame_hi_color = NULL;
     292        gfx_color_t *wnd_frame_sh_color = NULL;
     293        gfx_color_t *wnd_highlight_color = NULL;
     294        gfx_color_t *wnd_shadow_color = NULL;
     295        gfx_color_t *tbar_act_bg_color = NULL;
     296        gfx_color_t *tbar_inact_bg_color = NULL;
     297        gfx_color_t *tbar_act_text_color = NULL;
     298        gfx_color_t *tbar_inact_text_color = NULL;
     299        gfx_color_t *entry_fg_color = NULL;
     300        gfx_color_t *entry_bg_color = NULL;
     301        gfx_color_t *entry_act_bg_color = NULL;
     302        errno_t rc;
     303
     304        resource = calloc(1, sizeof(ui_resource_t));
     305        if (resource == NULL)
     306                return ENOMEM;
     307
     308        /* Create dummy font for text mode */
     309        rc = gfx_typeface_create(gc, &tface);
     310        if (rc != EOK)
     311                goto error;
     312
     313        rc = gfx_font_create_textmode(tface, &font);
     314        if (rc != EOK)
     315                goto error;
     316
     317        rc = gfx_color_new_ega(0x07, &btn_frame_color);
     318        if (rc != EOK)
     319                goto error;
     320
     321        rc = gfx_color_new_ega(0x20, &btn_face_color);
     322        if (rc != EOK)
     323                goto error;
     324
     325        rc = gfx_color_new_ega(0x20, &btn_text_color);
     326        if (rc != EOK)
     327                goto error;
     328
     329        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
     330            &btn_highlight_color);
     331        if (rc != EOK)
     332                goto error;
     333
     334        rc = gfx_color_new_ega(0x01, &btn_shadow_color);
     335        if (rc != EOK)
     336                goto error;
     337
     338        rc = gfx_color_new_ega(0x70, &wnd_face_color);
     339        if (rc != EOK)
     340                goto error;
     341
     342        rc = gfx_color_new_ega(0x70, &wnd_text_color);
     343        if (rc != EOK)
     344                goto error;
     345
     346        rc = gfx_color_new_ega(0x07, &wnd_sel_text_color);
     347        if (rc != EOK)
     348                goto error;
     349
     350        rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color);
     351        if (rc != EOK)
     352                goto error;
     353
     354        rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color);
     355        if (rc != EOK)
     356                goto error;
     357
     358        rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color);
     359        if (rc != EOK)
     360                goto error;
     361
     362        rc = gfx_color_new_ega(0x70, &wnd_highlight_color);
     363        if (rc != EOK)
     364                goto error;
     365
     366        rc = gfx_color_new_ega(0x01, &wnd_shadow_color);
     367        if (rc != EOK)
     368                goto error;
     369
     370        rc = gfx_color_new_ega(0x1f, &tbar_act_bg_color);
     371        if (rc != EOK)
     372                goto error;
     373
     374        rc = gfx_color_new_ega(0x1e, &tbar_act_text_color);
     375        if (rc != EOK)
     376                goto error;
     377
     378        rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color);
     379        if (rc != EOK)
     380                goto error;
     381
     382        rc = gfx_color_new_ega(0x07, &tbar_inact_text_color);
     383        if (rc != EOK)
     384                goto error;
     385
     386        rc = gfx_color_new_ega(0x1b, &entry_fg_color);
     387        if (rc != EOK)
     388                goto error;
     389
     390        rc = gfx_color_new_ega(0x1b, &entry_bg_color);
     391        if (rc != EOK)
     392                goto error;
     393
     394        rc = gfx_color_new_ega(0x37, &entry_act_bg_color);
     395        if (rc != EOK)
     396                goto error;
     397
     398        resource->gc = gc;
     399        resource->tface = tface;
     400        resource->font = font;
     401        resource->textmode = true;
     402
     403        resource->btn_frame_color = btn_frame_color;
     404        resource->btn_face_color = btn_face_color;
     405        resource->btn_text_color = btn_text_color;
     406        resource->btn_highlight_color = btn_highlight_color;
     407        resource->btn_shadow_color = btn_shadow_color;
     408
     409        resource->wnd_face_color = wnd_face_color;
     410        resource->wnd_text_color = wnd_text_color;
     411        resource->wnd_sel_text_color = wnd_sel_text_color;
     412        resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
     413        resource->wnd_frame_hi_color = wnd_frame_hi_color;
     414        resource->wnd_frame_sh_color = wnd_frame_sh_color;
     415        resource->wnd_highlight_color = wnd_highlight_color;
     416        resource->wnd_shadow_color = wnd_shadow_color;
     417
     418        resource->tbar_act_bg_color = tbar_act_bg_color;
     419        resource->tbar_act_text_color = tbar_act_text_color;
     420        resource->tbar_inact_bg_color = tbar_inact_bg_color;
     421        resource->tbar_inact_text_color = tbar_inact_text_color;
     422
     423        resource->entry_fg_color = entry_fg_color;
     424        resource->entry_bg_color = entry_bg_color;
     425        resource->entry_act_bg_color = entry_act_bg_color;
     426
     427        *rresource = resource;
     428        return EOK;
     429error:
     430        if (btn_frame_color != NULL)
     431                gfx_color_delete(btn_frame_color);
     432        if (btn_face_color != NULL)
     433                gfx_color_delete(btn_face_color);
     434        if (btn_text_color != NULL)
     435                gfx_color_delete(btn_text_color);
     436        if (btn_highlight_color != NULL)
     437                gfx_color_delete(btn_highlight_color);
     438        if (btn_shadow_color != NULL)
     439                gfx_color_delete(btn_shadow_color);
     440
     441        if (wnd_face_color != NULL)
     442                gfx_color_delete(wnd_face_color);
     443        if (wnd_text_color != NULL)
     444                gfx_color_delete(wnd_text_color);
     445        if (wnd_sel_text_color != NULL)
     446                gfx_color_delete(wnd_sel_text_color);
     447        if (wnd_sel_text_bg_color != NULL)
     448                gfx_color_delete(wnd_sel_text_bg_color);
     449        if (wnd_frame_hi_color != NULL)
     450                gfx_color_delete(wnd_frame_hi_color);
     451        if (wnd_frame_sh_color != NULL)
     452                gfx_color_delete(wnd_frame_sh_color);
     453        if (wnd_highlight_color != NULL)
     454                gfx_color_delete(wnd_highlight_color);
     455        if (wnd_shadow_color != NULL)
     456                gfx_color_delete(wnd_shadow_color);
     457
     458        if (tbar_act_bg_color != NULL)
     459                gfx_color_delete(tbar_act_bg_color);
     460        if (tbar_act_text_color != NULL)
     461                gfx_color_delete(tbar_act_text_color);
     462        if (tbar_inact_bg_color != NULL)
     463                gfx_color_delete(tbar_inact_bg_color);
     464        if (tbar_inact_text_color != NULL)
     465                gfx_color_delete(tbar_inact_text_color);
     466
     467        if (entry_fg_color != NULL)
     468                gfx_color_delete(entry_fg_color);
     469        if (entry_bg_color != NULL)
     470                gfx_color_delete(entry_bg_color);
     471        if (entry_act_bg_color != NULL)
     472                gfx_color_delete(entry_act_bg_color);
     473
     474        if (tface != NULL)
     475                gfx_typeface_destroy(tface);
     476        free(resource);
     477        return rc;
     478}
     479
     480/** Create new UI resource.
     481 *
     482 * @param gc Graphic context
     483 * @param textmode @c true if running in text mode
     484 * @param rresource Place to store pointer to new UI resource
     485 * @return EOK on success, ENOMEM if out of memory
     486 */
     487errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
     488    ui_resource_t **rresource)
     489{
     490        if (textmode)
     491                return ui_resource_create_text(gc, rresource);
     492        else
     493                return ui_resource_create_gfx(gc, rresource);
     494}
     495
    282496/** Destroy UI resource.
    283497 *
Note: See TracChangeset for help on using the changeset viewer.