Changeset 2ab8ab3 in mainline for uspace/lib/memgfx/test/memgfx.c


Ignore:
Timestamp:
2021-02-16T18:12:05Z (3 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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.