Ignore:
File:
1 edited

Legend:

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

    r1fa6292 r7470d97  
    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_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 opening and closing glyph bitmap */
     
    554585}
    555586
     587static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     588{
     589        return EOK;
     590}
     591
     592static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     593{
     594        return EOK;
     595}
     596
     597static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     598{
     599        return EOK;
     600}
     601
     602static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     603    gfx_bitmap_alloc_t *alloc, void **rbm)
     604{
     605        test_gc_t *tgc = (test_gc_t *) arg;
     606        testgc_bitmap_t *tbm;
     607
     608        tbm = calloc(1, sizeof(testgc_bitmap_t));
     609        if (tbm == NULL)
     610                return ENOMEM;
     611
     612        if (alloc == NULL) {
     613                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     614                    sizeof(uint32_t);
     615                tbm->alloc.off0 = 0;
     616                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     617                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     618                tbm->myalloc = true;
     619                if (tbm->alloc.pixels == NULL) {
     620                        free(tbm);
     621                        return ENOMEM;
     622                }
     623        } else {
     624                tbm->alloc = *alloc;
     625        }
     626
     627        tbm->tgc = tgc;
     628        tgc->bm_params = *params;
     629        tgc->bm_pixels = tbm->alloc.pixels;
     630        *rbm = (void *)tbm;
     631        return EOK;
     632}
     633
     634static errno_t testgc_bitmap_destroy(void *bm)
     635{
     636        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     637        if (tbm->myalloc)
     638                free(tbm->alloc.pixels);
     639        free(tbm);
     640        return EOK;
     641}
     642
     643static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     644    gfx_coord2_t *offs)
     645{
     646        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     647        tbm->tgc->bm_srect = *srect;
     648        tbm->tgc->bm_offs = *offs;
     649        return EOK;
     650}
     651
     652static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     653{
     654        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     655        *alloc = tbm->alloc;
     656        return EOK;
     657}
     658
    556659PCUT_EXPORT(glyph_bmp);
Note: See TracChangeset for help on using the changeset viewer.