HelenOS sources
This source file includes following definitions.
- dummygc_create
- dummygc_destroy
- dummygc_get_ctx
- dummygc_set_clip_rect
- dummygc_set_color
- dummygc_fill_rect
- dummygc_update
- dummygc_bitmap_create
- dummygc_bitmap_destroy
- dummygc_bitmap_render
- dummygc_bitmap_get_alloc
#include <gfx/context.h>
#include <gfx/coord.h>
#include <mem.h>
#include <stdbool.h>
#include <stdlib.h>
#include "../private/dummygc.h"
static errno_t dummygc_set_clip_rect(void *, gfx_rect_t *);
static errno_t dummygc_set_color(void *, gfx_color_t *);
static errno_t dummygc_fill_rect(void *, gfx_rect_t *);
static errno_t dummygc_update(void *);
static errno_t dummygc_bitmap_create(void *, gfx_bitmap_params_t *,
gfx_bitmap_alloc_t *, void **);
static errno_t dummygc_bitmap_destroy(void *);
static errno_t dummygc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
static errno_t dummygc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
gfx_context_ops_t dummygc_ops = {
.set_clip_rect = dummygc_set_clip_rect,
.set_color = dummygc_set_color,
.fill_rect = dummygc_fill_rect,
.update = dummygc_update,
.bitmap_create = dummygc_bitmap_create,
.bitmap_destroy = dummygc_bitmap_destroy,
.bitmap_render = dummygc_bitmap_render,
.bitmap_get_alloc = dummygc_bitmap_get_alloc
};
errno_t dummygc_create(dummy_gc_t **rdgc)
{
dummy_gc_t *dgc;
gfx_context_t *gc;
errno_t rc;
dgc = calloc(1, sizeof(dummy_gc_t));
if (dgc == NULL)
return ENOMEM;
rc = gfx_context_new(&dummygc_ops, dgc, &gc);
if (rc != EOK) {
free(dgc);
return rc;
}
dgc->gc = gc;
*rdgc = dgc;
return EOK;
}
void dummygc_destroy(dummy_gc_t *dgc)
{
gfx_context_delete(dgc->gc);
free(dgc);
}
gfx_context_t *dummygc_get_ctx(dummy_gc_t *dgc)
{
return dgc->gc;
}
static errno_t dummygc_set_clip_rect(void *arg, gfx_rect_t *rect)
{
(void) arg;
(void) rect;
return EOK;
}
static errno_t dummygc_set_color(void *arg, gfx_color_t *color)
{
(void) arg;
(void) color;
return EOK;
}
static errno_t dummygc_fill_rect(void *arg, gfx_rect_t *rect)
{
(void) arg;
(void) rect;
return EOK;
}
static errno_t dummygc_update(void *arg)
{
(void) arg;
return EOK;
}
static errno_t dummygc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
gfx_bitmap_alloc_t *alloc, void **rbm)
{
dummy_gc_t *dgc = (dummy_gc_t *) arg;
dummygc_bitmap_t *tbm;
tbm = calloc(1, sizeof(dummygc_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(sizeof(uint32_t),
(params->rect.p1.x - params->rect.p0.x) *
(params->rect.p1.y - params->rect.p0.y));
tbm->myalloc = true;
if (tbm->alloc.pixels == NULL) {
free(tbm);
return ENOMEM;
}
} else {
tbm->alloc = *alloc;
}
tbm->dgc = dgc;
dgc->bm_created = true;
dgc->bm_params = *params;
dgc->bm_pixels = tbm->alloc.pixels;
*rbm = (void *)tbm;
return EOK;
}
static errno_t dummygc_bitmap_destroy(void *bm)
{
dummygc_bitmap_t *tbm = (dummygc_bitmap_t *)bm;
if (tbm->myalloc)
free(tbm->alloc.pixels);
tbm->dgc->bm_destroyed = true;
free(tbm);
return EOK;
}
static errno_t dummygc_bitmap_render(void *bm, gfx_rect_t *srect,
gfx_coord2_t *offs)
{
dummygc_bitmap_t *tbm = (dummygc_bitmap_t *)bm;
tbm->dgc->bm_rendered = true;
tbm->dgc->bm_srect.p0.x = 0;
tbm->dgc->bm_srect.p0.y = 0;
tbm->dgc->bm_srect.p1.x = 0;
tbm->dgc->bm_srect.p1.y = 0;
tbm->dgc->bm_offs.x = 0;
tbm->dgc->bm_offs.y = 0;
if (srect != NULL)
tbm->dgc->bm_srect = *srect;
if (offs != NULL)
tbm->dgc->bm_offs = *offs;
return EOK;
}
static errno_t dummygc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
{
dummygc_bitmap_t *tbm = (dummygc_bitmap_t *)bm;
*alloc = tbm->alloc;
tbm->dgc->bm_got_alloc = true;
return EOK;
}
HelenOS homepage, sources at GitHub