Ignore:
File:
1 edited

Legend:

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

    r1fa6292 r297b1b3  
    3636#include <ui/resource.h>
    3737#include "../private/rbutton.h"
    38 #include "../private/testgc.h"
    3938
    4039PCUT_INIT;
    4140
    4241PCUT_TEST_SUITE(rbutton);
     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};
    4363
    4464static void test_rbutton_select(ui_rbutton_group_t *, void *, void *);
     
    5070static ui_rbutton_group_cb_t dummy_rbutton_group_cb = {
    5171};
     72
     73typedef struct {
     74        bool bm_created;
     75        bool bm_destroyed;
     76        gfx_bitmap_params_t bm_params;
     77        void *bm_pixels;
     78        gfx_rect_t bm_srect;
     79        gfx_coord2_t bm_offs;
     80        bool bm_rendered;
     81        bool bm_got_alloc;
     82} test_gc_t;
     83
     84typedef struct {
     85        test_gc_t *tgc;
     86        gfx_bitmap_alloc_t alloc;
     87        bool myalloc;
     88} testgc_bitmap_t;
    5289
    5390typedef struct {
     
    555592}
    556593
     594static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     595{
     596        (void) arg;
     597        (void) rect;
     598        return EOK;
     599}
     600
     601static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     602{
     603        (void) arg;
     604        (void) color;
     605        return EOK;
     606}
     607
     608static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     609{
     610        (void) arg;
     611        (void) rect;
     612        return EOK;
     613}
     614
     615static errno_t testgc_update(void *arg)
     616{
     617        (void) arg;
     618        return EOK;
     619}
     620
     621static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     622    gfx_bitmap_alloc_t *alloc, void **rbm)
     623{
     624        test_gc_t *tgc = (test_gc_t *) arg;
     625        testgc_bitmap_t *tbm;
     626
     627        tbm = calloc(1, sizeof(testgc_bitmap_t));
     628        if (tbm == NULL)
     629                return ENOMEM;
     630
     631        if (alloc == NULL) {
     632                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     633                    sizeof(uint32_t);
     634                tbm->alloc.off0 = 0;
     635                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     636                    (params->rect.p1.x - params->rect.p0.x) *
     637                    (params->rect.p1.y - params->rect.p0.y));
     638                tbm->myalloc = true;
     639                if (tbm->alloc.pixels == NULL) {
     640                        free(tbm);
     641                        return ENOMEM;
     642                }
     643        } else {
     644                tbm->alloc = *alloc;
     645        }
     646
     647        tbm->tgc = tgc;
     648        tgc->bm_created = true;
     649        tgc->bm_params = *params;
     650        tgc->bm_pixels = tbm->alloc.pixels;
     651        *rbm = (void *)tbm;
     652        return EOK;
     653}
     654
     655static errno_t testgc_bitmap_destroy(void *bm)
     656{
     657        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     658        if (tbm->myalloc)
     659                free(tbm->alloc.pixels);
     660        tbm->tgc->bm_destroyed = true;
     661        free(tbm);
     662        return EOK;
     663}
     664
     665static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     666    gfx_coord2_t *offs)
     667{
     668        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     669        tbm->tgc->bm_rendered = true;
     670        tbm->tgc->bm_srect = *srect;
     671        tbm->tgc->bm_offs = *offs;
     672        return EOK;
     673}
     674
     675static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     676{
     677        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     678        *alloc = tbm->alloc;
     679        tbm->tgc->bm_got_alloc = true;
     680        return EOK;
     681}
     682
    557683static void test_rbutton_select(ui_rbutton_group_t *group, void *arg,
    558684    void *barg)
Note: See TracChangeset for help on using the changeset viewer.