Ignore:
File:
1 edited

Legend:

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

    r1fa6292 r06b8383  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2020 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <str.h>
    3939#include "../private/glyph.h"
    40 #include "../private/testgc.h"
    4140
    4241PCUT_INIT;
    4342
    4443PCUT_TEST_SUITE(glyph);
     44
     45static errno_t testgc_set_color(void *, gfx_color_t *);
     46static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     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 test_ops = {
     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
    4675/** Test creating and destroying glyph */
     
    540569}
    541570
     571static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     572{
     573        return EOK;
     574}
     575
     576static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     577{
     578        return EOK;
     579}
     580
     581static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     582    gfx_bitmap_alloc_t *alloc, void **rbm)
     583{
     584        test_gc_t *tgc = (test_gc_t *) arg;
     585        testgc_bitmap_t *tbm;
     586
     587        tbm = calloc(1, sizeof(testgc_bitmap_t));
     588        if (tbm == NULL)
     589                return ENOMEM;
     590
     591        if (alloc == NULL) {
     592                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     593                    sizeof(uint32_t);
     594                tbm->alloc.off0 = 0;
     595                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     596                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     597                tbm->myalloc = true;
     598                if (tbm->alloc.pixels == NULL) {
     599                        free(tbm);
     600                        return ENOMEM;
     601                }
     602        } else {
     603                tbm->alloc = *alloc;
     604        }
     605
     606        tbm->tgc = tgc;
     607        tgc->bm_params = *params;
     608        tgc->bm_pixels = tbm->alloc.pixels;
     609        *rbm = (void *)tbm;
     610        return EOK;
     611}
     612
     613static errno_t testgc_bitmap_destroy(void *bm)
     614{
     615        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     616        if (tbm->myalloc)
     617                free(tbm->alloc.pixels);
     618        free(tbm);
     619        return EOK;
     620}
     621
     622static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     623    gfx_coord2_t *offs)
     624{
     625        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     626        tbm->tgc->bm_srect = *srect;
     627        tbm->tgc->bm_offs = *offs;
     628        return EOK;
     629}
     630
     631static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     632{
     633        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     634        *alloc = tbm->alloc;
     635        return EOK;
     636}
     637
    542638PCUT_EXPORT(glyph);
Note: See TracChangeset for help on using the changeset viewer.