Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/test/font.c

    r1fa6292 r7470d97  
    3434#include "../private/font.h"
    3535#include "../private/typeface.h"
    36 #include "../private/testgc.h"
    3736
    3837PCUT_INIT;
    3938
    4039PCUT_TEST_SUITE(font);
     40
     41static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
     42static errno_t testgc_set_color(void *, gfx_color_t *);
     43static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     44static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     45    gfx_bitmap_alloc_t *, void **);
     46static errno_t testgc_bitmap_destroy(void *);
     47static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     48static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     49
     50static gfx_context_ops_t test_ops = {
     51        .set_clip_rect = testgc_set_clip_rect,
     52        .set_color = testgc_set_color,
     53        .fill_rect = testgc_fill_rect,
     54        .bitmap_create = testgc_bitmap_create,
     55        .bitmap_destroy = testgc_bitmap_destroy,
     56        .bitmap_render = testgc_bitmap_render,
     57        .bitmap_get_alloc = testgc_bitmap_get_alloc
     58};
     59
     60typedef struct {
     61        gfx_bitmap_params_t bm_params;
     62        void *bm_pixels;
     63        gfx_rect_t bm_srect;
     64        gfx_coord2_t bm_offs;
     65} test_gc_t;
     66
     67typedef struct {
     68        test_gc_t *tgc;
     69        gfx_bitmap_alloc_t alloc;
     70        bool myalloc;
     71} testgc_bitmap_t;
    4172
    4273/** Test creating and destroying font */
     
    478509        height = 10;
    479510
    480         pixels = calloc(width * height, sizeof(uint32_t));
     511        pixels = calloc(sizeof(uint32_t), width * height);
    481512        PCUT_ASSERT_NOT_NULL(pixels);
    482513
     
    525556        }
    526557
    527         pixels = calloc(width * height, sizeof(uint32_t));
     558        pixels = calloc(sizeof(uint32_t), width * height);
    528559        PCUT_ASSERT_NOT_NULL(pixels);
    529560
     
    541572}
    542573
     574static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     575{
     576        return EOK;
     577}
     578
     579static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     580{
     581        return EOK;
     582}
     583
     584static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     585{
     586        return EOK;
     587}
     588
     589static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     590    gfx_bitmap_alloc_t *alloc, void **rbm)
     591{
     592        test_gc_t *tgc = (test_gc_t *) arg;
     593        testgc_bitmap_t *tbm;
     594
     595        tbm = calloc(1, sizeof(testgc_bitmap_t));
     596        if (tbm == NULL)
     597                return ENOMEM;
     598
     599        if (alloc == NULL) {
     600                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     601                    sizeof(uint32_t);
     602                tbm->alloc.off0 = 0;
     603                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     604                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     605                tbm->myalloc = true;
     606                if (tbm->alloc.pixels == NULL) {
     607                        free(tbm);
     608                        return ENOMEM;
     609                }
     610        } else {
     611                tbm->alloc = *alloc;
     612        }
     613
     614        tbm->tgc = tgc;
     615        tgc->bm_params = *params;
     616        tgc->bm_pixels = tbm->alloc.pixels;
     617        *rbm = (void *)tbm;
     618        return EOK;
     619}
     620
     621static errno_t testgc_bitmap_destroy(void *bm)
     622{
     623        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     624        if (tbm->myalloc)
     625                free(tbm->alloc.pixels);
     626        free(tbm);
     627        return EOK;
     628}
     629
     630static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     631    gfx_coord2_t *offs)
     632{
     633        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     634        tbm->tgc->bm_srect = *srect;
     635        tbm->tgc->bm_offs = *offs;
     636        return EOK;
     637}
     638
     639static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     640{
     641        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     642        *alloc = tbm->alloc;
     643        return EOK;
     644}
     645
    543646PCUT_EXPORT(font);
Note: See TracChangeset for help on using the changeset viewer.