Ignore:
File:
1 edited

Legend:

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

    r1fa6292 r7470d97  
    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_clip_rect(void *, gfx_rect_t *);
     46static errno_t testgc_set_color(void *, gfx_color_t *);
     47static errno_t testgc_fill_rect(void *, gfx_rect_t *);
     48static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
     49    gfx_bitmap_alloc_t *, void **);
     50static errno_t testgc_bitmap_destroy(void *);
     51static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
     52static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
     53
     54static gfx_context_ops_t test_ops = {
     55        .set_clip_rect = testgc_set_clip_rect,
     56        .set_color = testgc_set_color,
     57        .fill_rect = testgc_fill_rect,
     58        .bitmap_create = testgc_bitmap_create,
     59        .bitmap_destroy = testgc_bitmap_destroy,
     60        .bitmap_render = testgc_bitmap_render,
     61        .bitmap_get_alloc = testgc_bitmap_get_alloc
     62};
     63
     64typedef struct {
     65        gfx_bitmap_params_t bm_params;
     66        void *bm_pixels;
     67        gfx_rect_t bm_srect;
     68        gfx_coord2_t bm_offs;
     69} test_gc_t;
     70
     71typedef struct {
     72        test_gc_t *tgc;
     73        gfx_bitmap_alloc_t alloc;
     74        bool myalloc;
     75} testgc_bitmap_t;
    4576
    4677/** Test creating and destroying glyph */
     
    540571}
    541572
     573static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
     574{
     575        return EOK;
     576}
     577
     578static errno_t testgc_set_color(void *arg, gfx_color_t *color)
     579{
     580        return EOK;
     581}
     582
     583static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
     584{
     585        return EOK;
     586}
     587
     588static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
     589    gfx_bitmap_alloc_t *alloc, void **rbm)
     590{
     591        test_gc_t *tgc = (test_gc_t *) arg;
     592        testgc_bitmap_t *tbm;
     593
     594        tbm = calloc(1, sizeof(testgc_bitmap_t));
     595        if (tbm == NULL)
     596                return ENOMEM;
     597
     598        if (alloc == NULL) {
     599                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
     600                    sizeof(uint32_t);
     601                tbm->alloc.off0 = 0;
     602                tbm->alloc.pixels = calloc(sizeof(uint32_t),
     603                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y));
     604                tbm->myalloc = true;
     605                if (tbm->alloc.pixels == NULL) {
     606                        free(tbm);
     607                        return ENOMEM;
     608                }
     609        } else {
     610                tbm->alloc = *alloc;
     611        }
     612
     613        tbm->tgc = tgc;
     614        tgc->bm_params = *params;
     615        tgc->bm_pixels = tbm->alloc.pixels;
     616        *rbm = (void *)tbm;
     617        return EOK;
     618}
     619
     620static errno_t testgc_bitmap_destroy(void *bm)
     621{
     622        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     623        if (tbm->myalloc)
     624                free(tbm->alloc.pixels);
     625        free(tbm);
     626        return EOK;
     627}
     628
     629static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
     630    gfx_coord2_t *offs)
     631{
     632        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     633        tbm->tgc->bm_srect = *srect;
     634        tbm->tgc->bm_offs = *offs;
     635        return EOK;
     636}
     637
     638static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
     639{
     640        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
     641        *alloc = tbm->alloc;
     642        return EOK;
     643}
     644
    542645PCUT_EXPORT(glyph);
Note: See TracChangeset for help on using the changeset viewer.