Ignore:
File:
1 edited

Legend:

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

    r1fa6292 r120031a5  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2020 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    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_color(void *, gfx_color_t *);
     44static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     45static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     46    gfx_bitmap_alloc_t *, void **);
     47static errno_t testgc_bitmap_destroy(void *);
     48static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     49static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     50
     51static gfx_context_ops_t test_ops = {
     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;
    4572
    4673enum {
    4774        test_font_size = 9,
     75        test_font_flags = gff_bold_italic,
    4876        test_font_ascent = 4,
    4977        test_font_descent = 3,
     
    180208}
    181209
     210static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     211{
     212        return EOK;
     213}
     214
     215static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     216{
     217        return EOK;
     218}
     219
     220static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     221    gfx_bitmap_alloc_t *alloc, void **rbm)
     222{
     223        test_gc_t *tgc = (test_gc_t *) arg;
     224        testgc_bitmap_t *tbm;
     225
     226        tbm = calloc(1, sizeof(testgc_bitmap_t));
     227        if (tbm == NULL)
     228                return ENOMEM;
     229
     230        if (alloc == NULL) {
     231                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     232                    sizeof(uint32_t);
     233                tbm->alloc.off0 = 0;
     234                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     235                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     236                tbm->myalloc = true;
     237                if (tbm->alloc.pixels == NULL) {
     238                        free(tbm);
     239                        return ENOMEM;
     240                }
     241        } else {
     242                tbm->alloc = *alloc;
     243        }
     244
     245        tbm->tgc = tgc;
     246        tgc->bm_params = *params;
     247        tgc->bm_pixels = tbm->alloc.pixels;
     248        *rbm = (void *)tbm;
     249        return EOK;
     250}
     251
     252static errno_t testgc_bitmap_destroy(void *bm)
     253{
     254        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     255        if (tbm->myalloc)
     256                free(tbm->alloc.pixels);
     257        free(tbm);
     258        return EOK;
     259}
     260
     261static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     262    gfx_coord2_t *offs)
     263{
     264        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     265        tbm->tgc->bm_srect = *srect;
     266        tbm->tgc->bm_offs = *offs;
     267        return EOK;
     268}
     269
     270static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     271{
     272        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     273        *alloc = tbm->alloc;
     274        return EOK;
     275}
     276
    182277PCUT_EXPORT(tpf);
Note: See TracChangeset for help on using the changeset viewer.