Ignore:
File:
1 edited

Legend:

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

    r1fa6292 rdd65f4f7  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2020 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434#include <pcut/pcut.h>
    3535#include "../private/glyph_bmp.h"
    36 #include "../private/testgc.h"
    3736
    3837PCUT_INIT;
    3938
    4039PCUT_TEST_SUITE(glyph_bmp);
     40
     41static errno_t testgc_set_color(void *, gfx_color_t *);
     42static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     43static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     44    gfx_bitmap_alloc_t *, void **);
     45static errno_t testgc_bitmap_destroy(void *);
     46static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     47static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     48
     49static gfx_context_ops_t test_ops = {
     50        .set_color = testgc_set_color,
     51        .fill_rect = testgc_fill_rect,
     52        .bitmap_create = testgc_bitmap_create,
     53        .bitmap_destroy = testgc_bitmap_destroy,
     54        .bitmap_render = testgc_bitmap_render,
     55        .bitmap_get_alloc = testgc_bitmap_get_alloc
     56};
     57
     58typedef struct {
     59        gfx_bitmap_params_t bm_params;
     60        void *bm_pixels;
     61        gfx_rect_t bm_srect;
     62        gfx_coord2_t bm_offs;
     63} test_gc_t;
     64
     65typedef struct {
     66        test_gc_t *tgc;
     67        gfx_bitmap_alloc_t alloc;
     68        bool myalloc;
     69} testgc_bitmap_t;
    4170
    4271/** Test opening and closing glyph bitmap */
     
    554583}
    555584
     585static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     586{
     587        return EOK;
     588}
     589
     590static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     591{
     592        return EOK;
     593}
     594
     595static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     596    gfx_bitmap_alloc_t *alloc, void **rbm)
     597{
     598        test_gc_t *tgc = (test_gc_t *) arg;
     599        testgc_bitmap_t *tbm;
     600
     601        tbm = calloc(1, sizeof(testgc_bitmap_t));
     602        if (tbm == NULL)
     603                return ENOMEM;
     604
     605        if (alloc == NULL) {
     606                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     607                    sizeof(uint32_t);
     608                tbm->alloc.off0 = 0;
     609                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     610                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     611                tbm->myalloc = true;
     612                if (tbm->alloc.pixels == NULL) {
     613                        free(tbm);
     614                        return ENOMEM;
     615                }
     616        } else {
     617                tbm->alloc = *alloc;
     618        }
     619
     620        tbm->tgc = tgc;
     621        tgc->bm_params = *params;
     622        tgc->bm_pixels = tbm->alloc.pixels;
     623        *rbm = (void *)tbm;
     624        return EOK;
     625}
     626
     627static errno_t testgc_bitmap_destroy(void *bm)
     628{
     629        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     630        if (tbm->myalloc)
     631                free(tbm->alloc.pixels);
     632        free(tbm);
     633        return EOK;
     634}
     635
     636static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     637    gfx_coord2_t *offs)
     638{
     639        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     640        tbm->tgc->bm_srect = *srect;
     641        tbm->tgc->bm_offs = *offs;
     642        return EOK;
     643}
     644
     645static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     646{
     647        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     648        *alloc = tbm->alloc;
     649        return EOK;
     650}
     651
    556652PCUT_EXPORT(glyph_bmp);
Note: See TracChangeset for help on using the changeset viewer.