Changeset bea947f in mainline for uspace/srv


Ignore:
Timestamp:
2020-05-24T17:59:02Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b3b00b6
Parents:
ef20a91
Message:

Implement bitmap color key to allow transparent cursor background

This seems to be the simplest solution of them all. It will work
on any bit depth except 1 bit per pixel (monochrome), where we would
need to extend the bitmap with a bit mask instead.

Location:
uspace/srv/hid
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/cursor.c

    ref20a91 rbea947f  
    109109        gfx_bitmap_params_init(&bparams);
    110110        bparams.rect = cursor->rect;
     111        bparams.flags = bmpf_color_key;
     112        bparams.key_color = PIXEL(0, 0, 255, 255);
    111113
    112114        if (cursor->bitmap == NULL) {
  • uspace/srv/hid/display/types/display/window.h

    ref20a91 rbea947f  
    4242#include <gfx/context.h>
    4343#include <gfx/coord.h>
     44#include <io/pixel.h>
    4445#include <io/pixelmap.h>
    4546
     
    115116        /** Bounding rectangle */
    116117        gfx_rect_t rect;
     118        /** Bitmap flags */
     119        gfx_bitmap_flags_t flags;
     120        /** Key color */
     121        pixel_t key_color;
    117122} ds_window_bitmap_t;
    118123
  • uspace/srv/hid/display/window.c

    ref20a91 rbea947f  
    131131{
    132132        ds_window_t *wnd = (ds_window_t *) arg;
    133         ds_window_bitmap_t *cbm = NULL;
     133        ds_window_bitmap_t *wbm = NULL;
    134134        errno_t rc;
    135135
    136         cbm = calloc(1, sizeof(ds_window_bitmap_t));
    137         if (cbm == NULL)
     136        wbm = calloc(1, sizeof(ds_window_bitmap_t));
     137        if (wbm == NULL)
    138138                return ENOMEM;
    139139
    140140        rc = gfx_bitmap_create(ds_display_get_gc(wnd->display), params, alloc,
    141             &cbm->bitmap);
     141            &wbm->bitmap);
    142142        if (rc != EOK)
    143143                goto error;
    144144
    145         cbm->wnd = wnd;
    146         cbm->rect = params->rect;
    147         *rbm = (void *)cbm;
     145        wbm->wnd = wnd;
     146        wbm->rect = params->rect;
     147        wbm->flags = params->flags;
     148        wbm->key_color = params->key_color;
     149        *rbm = (void *)wbm;
    148150        return EOK;
    149151error:
    150         if (cbm != NULL)
    151                 free(cbm);
     152        if (wbm != NULL)
     153                free(wbm);
    152154        return rc;
    153155}
     
    160162static errno_t ds_window_bitmap_destroy(void *bm)
    161163{
    162         ds_window_bitmap_t *cbm = (ds_window_bitmap_t *)bm;
    163 
    164         gfx_bitmap_destroy(cbm->bitmap);
    165         free(cbm);
     164        ds_window_bitmap_t *wbm = (ds_window_bitmap_t *)bm;
     165
     166        gfx_bitmap_destroy(wbm->bitmap);
     167        free(wbm);
    166168        return EOK;
    167169}
     
    177179    gfx_coord2_t *offs0)
    178180{
    179         ds_window_bitmap_t *cbm = (ds_window_bitmap_t *)bm;
     181        ds_window_bitmap_t *wbm = (ds_window_bitmap_t *)bm;
    180182        gfx_coord2_t doffs;
    181183        gfx_coord2_t offs;
     
    192194        if (srect0 != NULL) {
    193195                /* Clip source rectangle to bitmap rectangle */
    194                 gfx_rect_clip(srect0, &cbm->rect, &srect);
     196                gfx_rect_clip(srect0, &wbm->rect, &srect);
    195197        } else {
    196198                /* Source is entire bitmap rectangle */
    197                 srect = cbm->rect;
     199                srect = wbm->rect;
    198200        }
    199201
     
    206208
    207209        /* Transform window rectangle back to bitmap coordinate system */
    208         gfx_rect_rtranslate(&offs, &cbm->wnd->rect, &swrect);
     210        gfx_rect_rtranslate(&offs, &wbm->wnd->rect, &swrect);
    209211
    210212        /* Clip so that transformed rectangle will be inside the window */
     
    212214
    213215        /* Offset for rendering on screen = window pos + offs */
    214         gfx_coord2_add(&cbm->wnd->dpos, &offs, &doffs);
     216        gfx_coord2_add(&wbm->wnd->dpos, &offs, &doffs);
    215217
    216218        /* Resulting rectangle on the screen we are drawing into */
    217219        gfx_rect_translate(&doffs, &crect, &drect);
    218220
    219         rc = gfx_bitmap_get_alloc(cbm->bitmap, &alloc);
     221        rc = gfx_bitmap_get_alloc(wbm->bitmap, &alloc);
    220222        if (rc != EOK)
    221223                return rc;
    222224
    223         pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x;
    224         pixelmap.height = cbm->rect.p1.y - cbm->rect.p0.y;
     225        pixelmap.width = wbm->rect.p1.x - wbm->rect.p0.x;
     226        pixelmap.height = wbm->rect.p1.y - wbm->rect.p0.y;
    225227        pixelmap.data = alloc.pixels;
    226228
    227229        /* Render a copy to the backbuffer */
    228         for (y = crect.p0.y; y < crect.p1.y; y++) {
    229                 for (x = crect.p0.x; x < crect.p1.x; x++) {
    230                         pixel = pixelmap_get_pixel(&pixelmap,
    231                             x - cbm->rect.p0.x, y - cbm->rect.p0.y);
    232                         pixelmap_put_pixel(&cbm->wnd->pixelmap,
    233                             x + offs.x - cbm->rect.p0.x + cbm->wnd->rect.p0.x,
    234                             y + offs.y - cbm->rect.p0.y + cbm->wnd->rect.p0.y,
    235                             pixel);
     230        if ((wbm->flags & bmpf_color_key) == 0) {
     231                for (y = crect.p0.y; y < crect.p1.y; y++) {
     232                        for (x = crect.p0.x; x < crect.p1.x; x++) {
     233                                pixel = pixelmap_get_pixel(&pixelmap,
     234                                    x - wbm->rect.p0.x, y - wbm->rect.p0.y);
     235                                pixelmap_put_pixel(&wbm->wnd->pixelmap,
     236                                    x + offs.x - wbm->rect.p0.x + wbm->wnd->rect.p0.x,
     237                                    y + offs.y - wbm->rect.p0.y + wbm->wnd->rect.p0.y,
     238                                    pixel);
     239                        }
    236240                }
     241        } else {
     242                for (y = crect.p0.y; y < crect.p1.y; y++) {
     243                        for (x = crect.p0.x; x < crect.p1.x; x++) {
     244                                pixel = pixelmap_get_pixel(&pixelmap,
     245                                    x - wbm->rect.p0.x, y - wbm->rect.p0.y);
     246                                if (pixel != wbm->key_color) {
     247                                        pixelmap_put_pixel(&wbm->wnd->pixelmap,
     248                                            x + offs.x - wbm->rect.p0.x +
     249                                            wbm->wnd->rect.p0.x,
     250                                            y + offs.y - wbm->rect.p0.y +
     251                                            wbm->wnd->rect.p0.y,
     252                                            pixel);
     253                                }
     254                        }
     255                }
    237256        }
    238257
    239258        /* Repaint this area of the display */
    240         return ds_display_paint(cbm->wnd->display, &drect);
     259        return ds_display_paint(wbm->wnd->display, &drect);
    241260}
    242261
     
    249268static errno_t ds_window_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
    250269{
    251         ds_window_bitmap_t *cbm = (ds_window_bitmap_t *)bm;
    252 
    253         return gfx_bitmap_get_alloc(cbm->bitmap, alloc);
     270        ds_window_bitmap_t *wbm = (ds_window_bitmap_t *)bm;
     271
     272        return gfx_bitmap_get_alloc(wbm->bitmap, alloc);
    254273}
    255274
  • uspace/srv/hid/rfb/main.c

    ref20a91 rbea947f  
    7272        gfx_bitmap_alloc_t alloc;
    7373        gfx_rect_t rect;
     74        gfx_bitmap_flags_t flags;
     75        pixel_t key_color;
    7476        bool myalloc;
    7577} rfb_bitmap_t;
     
    199201        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
    200202        rfbbm->rect = params->rect;
     203        rfbbm->flags = params->flags;
     204        rfbbm->key_color = params->key_color;
    201205
    202206        if (alloc == NULL) {
     
    278282        pbm.data = rfbbm->alloc.pixels;
    279283
    280         for (y = srect.p0.y; y < srect.p1.y; y++) {
    281                 for (x = srect.p0.x; x < srect.p1.x; x++) {
    282                         color = pixelmap_get_pixel(&pbm, x, y);
    283                         pixelmap_put_pixel(&rfbbm->rfb->rfb.framebuffer,
    284                             x + offs.x, y + offs.y, color);
     284        if ((rfbbm->flags & bmpf_color_key) == 0) {
     285                for (y = srect.p0.y; y < srect.p1.y; y++) {
     286                        for (x = srect.p0.x; x < srect.p1.x; x++) {
     287                                color = pixelmap_get_pixel(&pbm, x, y);
     288                                pixelmap_put_pixel(&rfbbm->rfb->rfb.framebuffer,
     289                                    x + offs.x, y + offs.y, color);
     290                        }
     291                }
     292        } else {
     293                for (y = srect.p0.y; y < srect.p1.y; y++) {
     294                        for (x = srect.p0.x; x < srect.p1.x; x++) {
     295                                color = pixelmap_get_pixel(&pbm, x, y);
     296                                if (color != rfbbm->key_color) {
     297                                        pixelmap_put_pixel(&rfbbm->rfb->rfb.framebuffer,
     298                                            x + offs.x, y + offs.y, color);
     299                                }
     300                        }
    285301                }
    286302        }
Note: See TracChangeset for help on using the changeset viewer.