Changeset f8375f7 in mainline for uspace/lib/memgfx/test/memgfx.c


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

Communicate memory GC updates via callback function

This is what we want in most use cases. Allows us to expose memory GC
ops directly without interposing on them (greatly simplifying the code).
The previous behavior is easily achieved by supplying the right callback
function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/memgfx/test/memgfx.c

    rcea9f0c rf8375f7  
    3434#include <gfx/render.h>
    3535#include <io/pixelmap.h>
     36#include <mem.h>
    3637#include <memgfx/memgc.h>
    3738#include <pcut/pcut.h>
     
    4041
    4142PCUT_TEST_SUITE(memgfx);
     43
     44static void test_update_rect(void *arg, gfx_rect_t *rect);
     45
     46typedef struct {
     47        /** True if update was called */
     48        bool update_called;
     49        /** Update rectangle */
     50        gfx_rect_t rect;
     51} test_update_t;
    4252
    4353/** Test creating and deleting a memory GC */
     
    5969        PCUT_ASSERT_NOT_NULL(alloc.pixels);
    6070
    61         rc = mem_gc_create(&rect, &alloc, &mgc);
     71        rc = mem_gc_create(&rect, &alloc, NULL, NULL, &mgc);
    6272        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    6373
     
    7282        gfx_rect_t rect;
    7383        gfx_rect_t frect;
    74         gfx_rect_t urect;
    7584        gfx_bitmap_alloc_t alloc;
    7685        gfx_context_t *gc;
     
    8089        pixel_t pixel;
    8190        pixel_t expected;
     91        test_update_t update;
    8292        errno_t rc;
    8393
     
    93103        PCUT_ASSERT_NOT_NULL(alloc.pixels);
    94104
    95         rc = mem_gc_create(&rect, &alloc, &mgc);
     105        rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc);
    96106        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    97107
     
    111121        frect.p1.x = 5;
    112122        frect.p1.y = 5;
     123
     124        memset(&update, 0, sizeof(update));
    113125
    114126        rc = gfx_fill_rect(gc, &frect);
     
    130142
    131143        /* Check that the update rect is equal to the filled rect */
    132         mem_gc_get_update_rect(mgc, &urect);
    133         PCUT_ASSERT_INT_EQUALS(frect.p0.x, urect.p0.x);
    134         PCUT_ASSERT_INT_EQUALS(frect.p0.y, urect.p0.y);
    135         PCUT_ASSERT_INT_EQUALS(frect.p1.x, urect.p1.x);
    136         PCUT_ASSERT_INT_EQUALS(frect.p1.y, urect.p1.y);
    137 
    138         /* Check that mem_gc_clear_update_rect() clears the update rect */
    139         mem_gc_clear_update_rect(mgc);
    140         mem_gc_get_update_rect(mgc, &urect);
    141         PCUT_ASSERT_TRUE(gfx_rect_is_empty(&urect));
     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);
    142149
    143150        /* TODO: Check clipping once memgc can support pitch != width etc. */
     
    152159        mem_gc_t *mgc;
    153160        gfx_rect_t rect;
    154         gfx_rect_t urect;
    155161        gfx_bitmap_alloc_t alloc;
    156162        gfx_context_t *gc;
     
    163169        pixel_t pixel;
    164170        pixel_t expected;
     171        test_update_t update;
    165172        errno_t rc;
    166173
     
    176183        PCUT_ASSERT_NOT_NULL(alloc.pixels);
    177184
    178         rc = mem_gc_create(&rect, &alloc, &mgc);
     185        rc = mem_gc_create(&rect, &alloc, test_update_rect, &update, &mgc);
    179186        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    180187
     
    211218        dpmap.height = rect.p1.y - rect.p0.y;
    212219        dpmap.data = alloc.pixels;
     220
     221        memset(&update, 0, sizeof(update));
    213222
    214223        /* Render the bitmap */
     
    229238
    230239        /* Check that the update rect is equal to the filled rect */
    231         mem_gc_get_update_rect(mgc, &urect);
    232         PCUT_ASSERT_INT_EQUALS(params.rect.p0.x, urect.p0.x);
    233         PCUT_ASSERT_INT_EQUALS(params.rect.p0.y, urect.p0.y);
    234         PCUT_ASSERT_INT_EQUALS(params.rect.p1.x, urect.p1.x);
    235         PCUT_ASSERT_INT_EQUALS(params.rect.p1.y, urect.p1.y);
    236 
    237         /* Check that mem_gc_clear_update_rect() clears the update rect */
    238         mem_gc_clear_update_rect(mgc);
    239         mem_gc_get_update_rect(mgc, &urect);
    240         PCUT_ASSERT_TRUE(gfx_rect_is_empty(&urect));
     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);
    241245
    242246        /* TODO: Check clipping once memgc can support pitch != width etc. */
     
    246250}
    247251
     252/** Called by memory GC when a rectangle is updated. */
     253static 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;
     259}
     260
    248261PCUT_EXPORT(memgfx);
Note: See TracChangeset for help on using the changeset viewer.