Ignore:
File:
1 edited

Legend:

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

    r1fa6292 r7470d97  
    3636#include "../private/font.h"
    3737#include "../private/typeface.h"
    38 #include "../private/testgc.h"
    3938
    4039PCUT_INIT;
     
    4241PCUT_TEST_SUITE(tpf);
    4342
    44 static const gfx_font_flags_t test_font_flags = gff_bold_italic;
     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_bitmap_create(void *, gfx_bitmap_params_t *,
     47    gfx_bitmap_alloc_t *, void **);
     48static errno_t testgc_bitmap_destroy(void *);
     49static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     50static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     51
     52static gfx_context_ops_t test_ops = {
     53        .set_clip_rect = testgc_set_clip_rect,
     54        .set_color = testgc_set_color,
     55        .fill_rect = testgc_fill_rect,
     56        .bitmap_create = testgc_bitmap_create,
     57        .bitmap_destroy = testgc_bitmap_destroy,
     58        .bitmap_render = testgc_bitmap_render,
     59        .bitmap_get_alloc = testgc_bitmap_get_alloc
     60};
     61
     62typedef struct {
     63        gfx_bitmap_params_t bm_params;
     64        void *bm_pixels;
     65        gfx_rect_t bm_srect;
     66        gfx_coord2_t bm_offs;
     67} test_gc_t;
     68
     69typedef struct {
     70        test_gc_t *tgc;
     71        gfx_bitmap_alloc_t alloc;
     72        bool myalloc;
     73} testgc_bitmap_t;
    4574
    4675enum {
    4776        test_font_size = 9,
     77        test_font_flags = gff_bold_italic,
    4878        test_font_ascent = 4,
    4979        test_font_descent = 3,
     
    180210}
    181211
     212static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     213{
     214        return EOK;
     215}
     216
     217static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     218{
     219        return EOK;
     220}
     221
     222static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     223{
     224        return EOK;
     225}
     226
     227static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     228    gfx_bitmap_alloc_t *alloc, void **rbm)
     229{
     230        test_gc_t *tgc = (test_gc_t *) arg;
     231        testgc_bitmap_t *tbm;
     232
     233        tbm = calloc(1, sizeof(testgc_bitmap_t));
     234        if (tbm == NULL)
     235                return ENOMEM;
     236
     237        if (alloc == NULL) {
     238                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     239                    sizeof(uint32_t);
     240                tbm->alloc.off0 = 0;
     241                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     242                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     243                tbm->myalloc = true;
     244                if (tbm->alloc.pixels == NULL) {
     245                        free(tbm);
     246                        return ENOMEM;
     247                }
     248        } else {
     249                tbm->alloc = *alloc;
     250        }
     251
     252        tbm->tgc = tgc;
     253        tgc->bm_params = *params;
     254        tgc->bm_pixels = tbm->alloc.pixels;
     255        *rbm = (void *)tbm;
     256        return EOK;
     257}
     258
     259static errno_t testgc_bitmap_destroy(void *bm)
     260{
     261        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     262        if (tbm->myalloc)
     263                free(tbm->alloc.pixels);
     264        free(tbm);
     265        return EOK;
     266}
     267
     268static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     269    gfx_coord2_t *offs)
     270{
     271        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     272        tbm->tgc->bm_srect = *srect;
     273        tbm->tgc->bm_offs = *offs;
     274        return EOK;
     275}
     276
     277static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     278{
     279        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     280        *alloc = tbm->alloc;
     281        return EOK;
     282}
     283
    182284PCUT_EXPORT(tpf);
Note: See TracChangeset for help on using the changeset viewer.