Changeset 2ab8ab3 in mainline for uspace/lib/memgfx


Ignore:
Timestamp:
2021-02-16T18:12:05Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
68a552f
Parents:
ef734b7
Message:

Client-side UI rendering

It is possible to turn on and off and if turned on, one can also
enable or disable window double buffering (currently both options
are build-time).

Location:
uspace/lib/memgfx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/memgfx/include/memgfx/memgc.h

    ref734b7 r2ab8ab3  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4646
    4747extern errno_t mem_gc_create(gfx_rect_t *, gfx_bitmap_alloc_t *,
    48     mem_gc_update_cb_t, void *, mem_gc_t **);
     48    mem_gc_invalidate_cb_t, mem_gc_update_cb_t, void *, mem_gc_t **);
    4949extern errno_t mem_gc_delete(mem_gc_t *);
    5050extern void mem_gc_retarget(mem_gc_t *, gfx_rect_t *, gfx_bitmap_alloc_t *);
  • uspace/lib/memgfx/include/types/memgfx/memgc.h

    ref734b7 r2ab8ab3  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4242typedef struct mem_gc mem_gc_t;
    4343
    44 typedef void (*mem_gc_update_cb_t)(void *, gfx_rect_t *);
     44typedef void (*mem_gc_invalidate_cb_t)(void *, gfx_rect_t *);
     45typedef void (*mem_gc_update_cb_t)(void *);
    4546
    4647#endif
  • uspace/lib/memgfx/private/memgc.h

    ref734b7 r2ab8ab3  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5151        /** Allocation info */
    5252        gfx_bitmap_alloc_t alloc;
     53        /** Invalidate callback */
     54        mem_gc_invalidate_cb_t invalidate;
    5355        /** Update callback */
    5456        mem_gc_update_cb_t update;
  • uspace/lib/memgfx/src/memgc.c

    ref734b7 r2ab8ab3  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5050static errno_t mem_gc_set_color(void *, gfx_color_t *);
    5151static errno_t mem_gc_fill_rect(void *, gfx_rect_t *);
     52static errno_t mem_gc_update(void *);
    5253static errno_t mem_gc_bitmap_create(void *, gfx_bitmap_params_t *,
    5354    gfx_bitmap_alloc_t *, void **);
     
    6061        .set_color = mem_gc_set_color,
    6162        .fill_rect = mem_gc_fill_rect,
     63        .update = mem_gc_update,
    6264        .bitmap_create = mem_gc_bitmap_create,
    6365        .bitmap_destroy = mem_gc_bitmap_destroy,
     
    119121}
    120122
     123/** Update memory GC.
     124 *
     125 * @param arg Memory GC
     126 *
     127 * @return EOK on success or an error code
     128 */
     129static errno_t mem_gc_update(void *arg)
     130{
     131        mem_gc_t *mgc = (mem_gc_t *) arg;
     132
     133        mgc->update(mgc->cb_arg);
     134        return EOK;
     135}
     136
    121137/** Create memory GC.
    122138 *
     
    132148 */
    133149errno_t mem_gc_create(gfx_rect_t *rect, gfx_bitmap_alloc_t *alloc,
    134     mem_gc_update_cb_t update_cb, void *cb_arg, mem_gc_t **rgc)
     150    mem_gc_invalidate_cb_t invalidate_cb, mem_gc_update_cb_t update_cb,
     151    void *cb_arg, mem_gc_t **rgc)
    135152{
    136153        mem_gc_t *mgc = NULL;
     
    152169        mgc->alloc = *alloc;
    153170
     171        mgc->invalidate = invalidate_cb;
    154172        mgc->update = update_cb;
    155173        mgc->cb_arg = cb_arg;
     
    205223static void mem_gc_invalidate_rect(mem_gc_t *mgc, gfx_rect_t *rect)
    206224{
    207         mgc->update(mgc->cb_arg, rect);
     225        mgc->invalidate(mgc->cb_arg, rect);
    208226}
    209227
  • uspace/lib/memgfx/test/memgfx.c

    ref734b7 r2ab8ab3  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4242PCUT_TEST_SUITE(memgfx);
    4343
    44 static void test_update_rect(void *arg, gfx_rect_t *rect);
     44static void test_invalidate_rect(void *arg, gfx_rect_t *rect);
     45static void test_update(void *arg);
    4546
    4647typedef struct {
     48        /** True if invalidate was called */
     49        bool invalidate_called;
     50        /** Invalidate rectangle */
     51        gfx_rect_t inv_rect;
    4752        /** True if update was called */
    4853        bool update_called;
    49         /** Update rectangle */
    50         gfx_rect_t rect;
    51 } test_update_t;
     54} test_resp_t;
    5255
    5356/** Test creating and deleting a memory GC */
     
    6972        PCUT_ASSERT_NOT_NULL(alloc.pixels);
    7073
    71         rc = mem_gc_create(&rect, &alloc, NULL, NULL, &mgc);
     74        rc = mem_gc_create(&rect, &alloc, NULL, NULL, NULL, &mgc);
    7275        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    7376
     
    8992        pixel_t pixel;
    9093        pixel_t expected;
    91         test_update_t update;
     94        test_resp_t resp;
    9295        errno_t rc;
    9396
     
    103106        PCUT_ASSERT_NOT_NULL(alloc.pixels);
    104107
    105         rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc);
     108        rc = mem_gc_create(&rect, &alloc, test_invalidate_rect,
     109            test_update, &resp, &mgc);
    106110        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    107111
     
    122126        frect.p1.y = 5;
    123127
    124         memset(&update, 0, sizeof(update));
     128        memset(&resp, 0, sizeof(resp));
    125129
    126130        rc = gfx_fill_rect(gc, &frect);
     
    141145        }
    142146
    143         /* Check that the update rect is equal to the filled rect */
    144         PCUT_ASSERT_TRUE(update.update_called);
    145         PCUT_ASSERT_INT_EQUALS(frect.p0.x, update.rect.p0.x);
    146         PCUT_ASSERT_INT_EQUALS(frect.p0.y, update.rect.p0.y);
    147         PCUT_ASSERT_INT_EQUALS(frect.p1.x, update.rect.p1.x);
    148         PCUT_ASSERT_INT_EQUALS(frect.p1.y, update.rect.p1.y);
     147        /* Check that the invalidate rect is equal to the filled rect */
     148        PCUT_ASSERT_TRUE(resp.invalidate_called);
     149        PCUT_ASSERT_INT_EQUALS(frect.p0.x, resp.inv_rect.p0.x);
     150        PCUT_ASSERT_INT_EQUALS(frect.p0.y, resp.inv_rect.p0.y);
     151        PCUT_ASSERT_INT_EQUALS(frect.p1.x, resp.inv_rect.p1.x);
     152        PCUT_ASSERT_INT_EQUALS(frect.p1.y, resp.inv_rect.p1.y);
    149153
    150154        /* TODO: Check clipping once memgc can support pitch != width etc. */
     
    169173        pixel_t pixel;
    170174        pixel_t expected;
    171         test_update_t update;
     175        test_resp_t resp;
    172176        errno_t rc;
    173177
     
    183187        PCUT_ASSERT_NOT_NULL(alloc.pixels);
    184188
    185         rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc);
     189        rc = mem_gc_create(&rect, &alloc, test_invalidate_rect,
     190            test_update, &resp, &mgc);
    186191        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    187192
     
    191196        /* Create bitmap */
    192197
     198        gfx_bitmap_params_init(&params);
    193199        params.rect.p0.x = 0;
    194200        params.rect.p0.y = 0;
     
    219225        dpmap.data = alloc.pixels;
    220226
    221         memset(&update, 0, sizeof(update));
     227        memset(&resp, 0, sizeof(resp));
    222228
    223229        /* Render the bitmap */
     
    237243        }
    238244
    239         /* Check that the update rect is equal to the filled rect */
    240         PCUT_ASSERT_TRUE(update.update_called);
    241         PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, update.rect.p0.x);
    242         PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, update.rect.p0.y);
    243         PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, update.rect.p1.x);
    244         PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, update.rect.p1.y);
     245        /* Check that the invalidate rect is equal to the filled rect */
     246        PCUT_ASSERT_TRUE(resp.invalidate_called);
     247        PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, resp.inv_rect.p0.x);
     248        PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, resp.inv_rect.p0.y);
     249        PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, resp.inv_rect.p1.x);
     250        PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, resp.inv_rect.p1.y);
    245251
    246252        /* TODO: Check clipping once memgc can support pitch != width etc. */
     
    250256}
    251257
    252 /** Called by memory GC when a rectangle is updated. */
    253 static void test_update_rect(void *arg, gfx_rect_t *rect)
    254 {
    255         test_update_t *update = (test_update_t *)arg;
    256 
    257         update->update_called = true;
    258         update->rect = *rect;
     258/** Test gfx_update() on a memory GC */
     259PCUT_TEST(gfx_update)
     260{
     261        mem_gc_t *mgc;
     262        gfx_rect_t rect;
     263        gfx_bitmap_alloc_t alloc;
     264        gfx_context_t *gc;
     265        test_resp_t resp;
     266        errno_t rc;
     267
     268        /* Bounding rectangle for memory GC */
     269        rect.p0.x = 0;
     270        rect.p0.y = 0;
     271        rect.p1.x = 10;
     272        rect.p1.y = 10;
     273
     274        alloc.pitch = (rect.p1.x - rect.p0.x) * sizeof(uint32_t);
     275        alloc.off0 = 0;
     276        alloc.pixels = calloc(1, alloc.pitch * (rect.p1.y - rect.p0.y));
     277        PCUT_ASSERT_NOT_NULL(alloc.pixels);
     278
     279        rc = mem_gc_create(&rect, &alloc, test_invalidate_rect,
     280            test_update, &resp, &mgc);
     281        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     282
     283        gc = mem_gc_get_ctx(mgc);
     284        PCUT_ASSERT_NOT_NULL(gc);
     285
     286        memset(&resp, 0, sizeof(resp));
     287        PCUT_ASSERT_FALSE(resp.update_called);
     288
     289        gfx_update(gc);
     290        PCUT_ASSERT_TRUE(resp.update_called);
     291
     292        mem_gc_delete(mgc);
     293        free(alloc.pixels);
     294}
     295
     296/** Called by memory GC when a rectangle is modified. */
     297static void test_invalidate_rect(void *arg, gfx_rect_t *rect)
     298{
     299        test_resp_t *resp = (test_resp_t *)arg;
     300
     301        resp->invalidate_called = true;
     302        resp->inv_rect = *rect;
     303}
     304
     305/** Called by memory GC when update is called. */
     306static void test_update(void *arg)
     307{
     308        test_resp_t *resp = (test_resp_t *)arg;
     309
     310        resp->update_called = true;
    259311}
    260312
Note: See TracChangeset for help on using the changeset viewer.