HelenOS sources
This source file includes following definitions.
- testgc_set_clip_rect
- testgc_set_color
- testgc_fill_rect
- testgc_bitmap_create
- testgc_bitmap_destroy
- testgc_bitmap_render
- testgc_bitmap_get_alloc
typedef struct {
        gfx_bitmap_params_t bm_params;
        void *bm_pixels;
        gfx_rect_t bm_srect;
        gfx_coord2_t bm_offs;
} test_gc_t;
typedef struct {
        test_gc_t *tgc;
        gfx_bitmap_alloc_t alloc;
        bool myalloc;
} testgc_bitmap_t;
static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
{
        return EOK;
}
static errno_t testgc_set_color(void *arg, gfx_color_t *color)
{
        return EOK;
}
static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
{
        return EOK;
}
static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
    gfx_bitmap_alloc_t *alloc, void **rbm)
{
        test_gc_t *tgc = (test_gc_t *) arg;
        testgc_bitmap_t *tbm;
        tbm = calloc(1, sizeof(testgc_bitmap_t));
        if (tbm == NULL)
                return ENOMEM;
        if (alloc == NULL) {
                tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
                    sizeof(uint32_t);
                tbm->alloc.off0 = 0;
                tbm->alloc.pixels = calloc(
                    tbm->alloc.pitch * (params->rect.p1.y - params->rect.p0.y),
                    sizeof(uint32_t));
                tbm->myalloc = true;
                if (tbm->alloc.pixels == NULL) {
                        free(tbm);
                        return ENOMEM;
                }
        } else {
                tbm->alloc = *alloc;
        }
        tbm->tgc = tgc;
        tgc->bm_params = *params;
        tgc->bm_pixels = tbm->alloc.pixels;
        *rbm = (void *)tbm;
        return EOK;
}
static errno_t testgc_bitmap_destroy(void *bm)
{
        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
        if (tbm->myalloc)
                free(tbm->alloc.pixels);
        free(tbm);
        return EOK;
}
static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
    gfx_coord2_t *offs)
{
        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
        tbm->tgc->bm_srect = *srect;
        tbm->tgc->bm_offs = *offs;
        return EOK;
}
static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
{
        testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
        *alloc = tbm->alloc;
        return EOK;
}
static gfx_context_ops_t test_ops = {
        .set_clip_rect = testgc_set_clip_rect,
        .set_color = testgc_set_color,
        .fill_rect = testgc_fill_rect,
        .bitmap_create = testgc_bitmap_create,
        .bitmap_destroy = testgc_bitmap_destroy,
        .bitmap_render = testgc_bitmap_render,
        .bitmap_get_alloc = testgc_bitmap_get_alloc
};
HelenOS homepage, sources at GitHub