Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/test/label.c

    r1fa6292 r7470d97  
    3636#include <ui/resource.h>
    3737#include "../private/label.h"
    38 #include "../private/testgc.h"
    3938
    4039PCUT_INIT;
    4140
    4241PCUT_TEST_SUITE(label);
     42
     43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
     44static errno_t testgc_set_color(void *, gfx_color_t *);
     45static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     46static errno_t testgc_update(void *);
     47static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     48    gfx_bitmap_alloc_t *, void **);
     49static errno_t testgc_bitmap_destroy(void *);
     50static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     51static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     52
     53static gfx_context_ops_t ops = {
     54        .set_clip_rect = testgc_set_clip_rect,
     55        .set_color = testgc_set_color,
     56        .fill_rect = testgc_fill_rect,
     57        .update = testgc_update,
     58        .bitmap_create = testgc_bitmap_create,
     59        .bitmap_destroy = testgc_bitmap_destroy,
     60        .bitmap_render = testgc_bitmap_render,
     61        .bitmap_get_alloc = testgc_bitmap_get_alloc
     62};
     63
     64typedef struct {
     65        bool bm_created;
     66        bool bm_destroyed;
     67        gfx_bitmap_params_t bm_params;
     68        void *bm_pixels;
     69        gfx_rect_t bm_srect;
     70        gfx_coord2_t bm_offs;
     71        bool bm_rendered;
     72        bool bm_got_alloc;
     73} test_gc_t;
     74
     75typedef struct {
     76        test_gc_t *tgc;
     77        gfx_bitmap_alloc_t alloc;
     78        bool myalloc;
     79} testgc_bitmap_t;
    4380
    4481typedef struct {
     
    176213}
    177214
     215static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     216{
     217        (void) arg;
     218        (void) rect;
     219        return EOK;
     220}
     221
     222static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     223{
     224        (void) arg;
     225        (void) color;
     226        return EOK;
     227}
     228
     229static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     230{
     231        (void) arg;
     232        (void) rect;
     233        return EOK;
     234}
     235
     236static errno_t testgc_update(void *arg)
     237{
     238        (void) arg;
     239        return EOK;
     240}
     241
     242static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     243    gfx_bitmap_alloc_t *alloc, void **rbm)
     244{
     245        test_gc_t *tgc = (test_gc_t *) arg;
     246        testgc_bitmap_t *tbm;
     247
     248        tbm = calloc(1, sizeof(testgc_bitmap_t));
     249        if (tbm == NULL)
     250                return ENOMEM;
     251
     252        if (alloc == NULL) {
     253                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     254                    sizeof(uint32_t);
     255                tbm->alloc.off0 = 0;
     256                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     257                    (params->rect.p1.x - params->rect.p0.x) *
     258                    (params->rect.p1.y - params->rect.p0.y));
     259                tbm->myalloc = true;
     260                if (tbm->alloc.pixels == NULL) {
     261                        free(tbm);
     262                        return ENOMEM;
     263                }
     264        } else {
     265                tbm->alloc = *alloc;
     266        }
     267
     268        tbm->tgc = tgc;
     269        tgc->bm_created = true;
     270        tgc->bm_params = *params;
     271        tgc->bm_pixels = tbm->alloc.pixels;
     272        *rbm = (void *)tbm;
     273        return EOK;
     274}
     275
     276static errno_t testgc_bitmap_destroy(void *bm)
     277{
     278        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     279        if (tbm->myalloc)
     280                free(tbm->alloc.pixels);
     281        tbm->tgc->bm_destroyed = true;
     282        free(tbm);
     283        return EOK;
     284}
     285
     286static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     287    gfx_coord2_t *offs)
     288{
     289        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     290        tbm->tgc->bm_rendered = true;
     291        tbm->tgc->bm_srect = *srect;
     292        tbm->tgc->bm_offs = *offs;
     293        return EOK;
     294}
     295
     296static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     297{
     298        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     299        *alloc = tbm->alloc;
     300        tbm->tgc->bm_got_alloc = true;
     301        return EOK;
     302}
     303
    178304PCUT_EXPORT(label);
Note: See TracChangeset for help on using the changeset viewer.