HelenOS sources
This source file includes following definitions.
- xlate_gc_set_clip_rect
- xlate_gc_set_color
- xlate_gc_fill_rect
- xlate_gc_update
- xlate_gc_create
- xlate_gc_delete
- xlate_gc_get_ctx
- xlate_gc_bitmap_create
- xlate_gc_bitmap_destroy
- xlate_gc_bitmap_render
- xlate_gc_bitmap_get_alloc
- xlate_gc_cursor_get_pos
- xlate_gc_cursor_set_pos
- xlate_gc_cursor_set_visible
- xlate_gc_set_off
#include <assert.h>
#include <gfx/color.h>
#include <gfx/context.h>
#include <gfx/cursor.h>
#include <gfx/render.h>
#include <memgfx/xlategc.h>
#include <stdlib.h>
#include "../private/xlategc.h"
static errno_t xlate_gc_set_clip_rect(void *, gfx_rect_t *);
static errno_t xlate_gc_set_color(void *, gfx_color_t *);
static errno_t xlate_gc_fill_rect(void *, gfx_rect_t *);
static errno_t xlate_gc_update(void *);
static errno_t xlate_gc_bitmap_create(void *, gfx_bitmap_params_t *,
gfx_bitmap_alloc_t *, void **);
static errno_t xlate_gc_bitmap_destroy(void *);
static errno_t xlate_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
static errno_t xlate_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
static errno_t xlate_gc_cursor_get_pos(void *, gfx_coord2_t *);
static errno_t xlate_gc_cursor_set_pos(void *, gfx_coord2_t *);
static errno_t xlate_gc_cursor_set_visible(void *, bool);
gfx_context_ops_t xlate_gc_ops = {
.set_clip_rect = xlate_gc_set_clip_rect,
.set_color = xlate_gc_set_color,
.fill_rect = xlate_gc_fill_rect,
.update = xlate_gc_update,
.bitmap_create = xlate_gc_bitmap_create,
.bitmap_destroy = xlate_gc_bitmap_destroy,
.bitmap_render = xlate_gc_bitmap_render,
.bitmap_get_alloc = xlate_gc_bitmap_get_alloc,
.cursor_get_pos = xlate_gc_cursor_get_pos,
.cursor_set_pos = xlate_gc_cursor_set_pos,
.cursor_set_visible = xlate_gc_cursor_set_visible
};
static errno_t xlate_gc_set_clip_rect(void *arg, gfx_rect_t *rect)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
gfx_rect_t crect;
if (rect != NULL) {
gfx_rect_translate(&xgc->off, rect, &crect);
return gfx_set_clip_rect(xgc->bgc, &crect);
} else {
return gfx_set_clip_rect(xgc->bgc, NULL);
}
}
static errno_t xlate_gc_set_color(void *arg, gfx_color_t *color)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
return gfx_set_color(xgc->bgc, color);
}
static errno_t xlate_gc_fill_rect(void *arg, gfx_rect_t *rect)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
gfx_rect_t frect;
gfx_rect_translate(&xgc->off, rect, &frect);
return gfx_fill_rect(xgc->bgc, &frect);
}
static errno_t xlate_gc_update(void *arg)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
return gfx_update(xgc->bgc);
}
errno_t xlate_gc_create(gfx_coord2_t *off, gfx_context_t *bgc,
xlate_gc_t **rgc)
{
xlate_gc_t *xgc = NULL;
gfx_context_t *gc = NULL;
errno_t rc;
xgc = calloc(1, sizeof(xlate_gc_t));
if (xgc == NULL) {
rc = ENOMEM;
goto error;
}
rc = gfx_context_new(&xlate_gc_ops, xgc, &gc);
if (rc != EOK)
goto error;
xgc->bgc = bgc;
xgc->gc = gc;
xgc->off = *off;
*rgc = xgc;
return EOK;
error:
if (xgc != NULL)
free(xgc);
gfx_context_delete(gc);
return rc;
}
errno_t xlate_gc_delete(xlate_gc_t *xgc)
{
errno_t rc;
rc = gfx_context_delete(xgc->gc);
if (rc != EOK)
return rc;
free(xgc);
return EOK;
}
gfx_context_t *xlate_gc_get_ctx(xlate_gc_t *xgc)
{
return xgc->gc;
}
errno_t xlate_gc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
gfx_bitmap_alloc_t *alloc, void **rbm)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
xlate_gc_bitmap_t *xbm;
gfx_bitmap_t *bm = NULL;
errno_t rc;
xbm = calloc(1, sizeof(xlate_gc_bitmap_t));
if (xbm == NULL)
return ENOMEM;
rc = gfx_bitmap_create(xgc->bgc, params, alloc, &bm);
if (rc != EOK) {
free(xbm);
return rc;
}
xbm->xgc = xgc;
xbm->bm = bm;
*rbm = (void *)xbm;
return EOK;
}
static errno_t xlate_gc_bitmap_destroy(void *bm)
{
xlate_gc_bitmap_t *xbm = (xlate_gc_bitmap_t *)bm;
errno_t rc;
rc = gfx_bitmap_destroy(xbm->bm);
free(xbm);
return rc;
}
static errno_t xlate_gc_bitmap_render(void *bm, gfx_rect_t *srect0,
gfx_coord2_t *offs0)
{
xlate_gc_bitmap_t *xbm = (xlate_gc_bitmap_t *)bm;
gfx_coord2_t offs;
if (offs0 != NULL)
gfx_coord2_add(offs0, &xbm->xgc->off, &offs);
else
offs = xbm->xgc->off;
return gfx_bitmap_render(xbm->bm, srect0, &offs);
}
static errno_t xlate_gc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
{
xlate_gc_bitmap_t *xbm = (xlate_gc_bitmap_t *)bm;
return gfx_bitmap_get_alloc(xbm->bm, alloc);
}
static errno_t xlate_gc_cursor_get_pos(void *arg, gfx_coord2_t *pos)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
gfx_coord2_t cpos;
errno_t rc;
rc = gfx_cursor_get_pos(xgc->bgc, &cpos);
if (rc != EOK)
return rc;
gfx_coord2_subtract(&cpos, &xgc->off, pos);
return EOK;
}
static errno_t xlate_gc_cursor_set_pos(void *arg, gfx_coord2_t *pos)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
gfx_coord2_t cpos;
gfx_coord2_add(pos, &xgc->off, &cpos);
return gfx_cursor_set_pos(xgc->bgc, &cpos);
}
static errno_t xlate_gc_cursor_set_visible(void *arg, bool visible)
{
xlate_gc_t *xgc = (xlate_gc_t *) arg;
return gfx_cursor_set_visible(xgc->bgc, visible);
}
void xlate_gc_set_off(xlate_gc_t *xgc, gfx_coord2_t *off)
{
xgc->off = *off;
}
HelenOS homepage, sources at GitHub