HelenOS sources
This source file includes following definitions.
- ds_clonegc_set_clip_rect
- ds_clonegc_set_color
- ds_clonegc_fill_rect
- ds_clonegc_create
- ds_clonegc_delete
- ds_clonegc_add_output
- ds_clonegc_get_ctx
- ds_clonegc_bitmap_create
- ds_clonegc_bitmap_destroy
- ds_clonegc_bitmap_render
- ds_clonegc_bitmap_get_alloc
- ds_clonegc_first_output
- ds_clonegc_next_output
- ds_clonegc_first_bitmap
- ds_clonegc_next_bitmap
- ds_clonegc_bitmap_first_obm
- ds_clonegc_bitmap_next_obm
- ds_clonegc_outbitmap_create
- ds_clonegc_outbitmap_destroy
- ds_clonegc_bitmap_add_output
#include <assert.h>
#include <gfx/color.h>
#include <gfx/context.h>
#include <gfx/render.h>
#include <stdlib.h>
#include "clonegc.h"
static errno_t ds_clonegc_set_clip_rect(void *, gfx_rect_t *);
static errno_t ds_clonegc_set_color(void *, gfx_color_t *);
static errno_t ds_clonegc_fill_rect(void *, gfx_rect_t *);
static errno_t ds_clonegc_bitmap_create(void *, gfx_bitmap_params_t *,
gfx_bitmap_alloc_t *, void **);
static errno_t ds_clonegc_bitmap_destroy(void *);
static errno_t ds_clonegc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
static errno_t ds_clonegc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
static ds_clonegc_output_t *ds_clonegc_first_output(ds_clonegc_t *);
static ds_clonegc_output_t *ds_clonegc_next_output(ds_clonegc_output_t *);
static ds_clonegc_bitmap_t *ds_clonegc_first_bitmap(ds_clonegc_t *);
static ds_clonegc_bitmap_t *ds_clonegc_next_bitmap(ds_clonegc_bitmap_t *);
static ds_clonegc_outbitmap_t *ds_clonegc_bitmap_first_obm(ds_clonegc_bitmap_t *);
static ds_clonegc_outbitmap_t *ds_clonegc_bitmap_next_obm(ds_clonegc_outbitmap_t *);
static errno_t ds_clonegc_outbitmap_create(ds_clonegc_output_t *,
ds_clonegc_bitmap_t *, gfx_bitmap_t *);
static errno_t ds_clonegc_outbitmap_destroy(ds_clonegc_outbitmap_t *);
static errno_t ds_clonegc_bitmap_add_output(ds_clonegc_bitmap_t *,
ds_clonegc_output_t *);
gfx_context_ops_t ds_clonegc_ops = {
.set_clip_rect = ds_clonegc_set_clip_rect,
.set_color = ds_clonegc_set_color,
.fill_rect = ds_clonegc_fill_rect,
.bitmap_create = ds_clonegc_bitmap_create,
.bitmap_destroy = ds_clonegc_bitmap_destroy,
.bitmap_render = ds_clonegc_bitmap_render,
.bitmap_get_alloc = ds_clonegc_bitmap_get_alloc
};
static errno_t ds_clonegc_set_clip_rect(void *arg, gfx_rect_t *rect)
{
ds_clonegc_t *cgc = (ds_clonegc_t *)arg;
ds_clonegc_output_t *output;
errno_t rc;
output = ds_clonegc_first_output(cgc);
while (output != NULL) {
rc = gfx_set_clip_rect(output->gc, rect);
if (rc != EOK)
return rc;
output = ds_clonegc_next_output(output);
}
return EOK;
}
static errno_t ds_clonegc_set_color(void *arg, gfx_color_t *color)
{
ds_clonegc_t *cgc = (ds_clonegc_t *)arg;
ds_clonegc_output_t *output;
errno_t rc;
output = ds_clonegc_first_output(cgc);
while (output != NULL) {
rc = gfx_set_color(output->gc, color);
if (rc != EOK)
return rc;
output = ds_clonegc_next_output(output);
}
return EOK;
}
static errno_t ds_clonegc_fill_rect(void *arg, gfx_rect_t *rect)
{
ds_clonegc_t *cgc = (ds_clonegc_t *)arg;
ds_clonegc_output_t *output;
errno_t rc;
output = ds_clonegc_first_output(cgc);
while (output != NULL) {
rc = gfx_fill_rect(output->gc, rect);
if (rc != EOK)
return rc;
output = ds_clonegc_next_output(output);
}
return EOK;
}
errno_t ds_clonegc_create(gfx_context_t *outgc, ds_clonegc_t **rgc)
{
ds_clonegc_t *cgc = NULL;
gfx_context_t *gc = NULL;
errno_t rc;
cgc = calloc(1, sizeof(ds_clonegc_t));
if (cgc == NULL) {
rc = ENOMEM;
goto error;
}
rc = gfx_context_new(&ds_clonegc_ops, cgc, &gc);
if (rc != EOK)
goto error;
cgc->gc = gc;
list_initialize(&cgc->outputs);
list_initialize(&cgc->bitmaps);
if (outgc != NULL) {
rc = ds_clonegc_add_output(cgc, outgc);
if (rc != EOK)
goto error;
}
*rgc = cgc;
return EOK;
error:
if (cgc != NULL)
free(cgc);
if (gc != NULL)
gfx_context_delete(gc);
return rc;
}
errno_t ds_clonegc_delete(ds_clonegc_t *cgc)
{
errno_t rc;
rc = gfx_context_delete(cgc->gc);
if (rc != EOK)
return rc;
free(cgc);
return EOK;
}
errno_t ds_clonegc_add_output(ds_clonegc_t *cgc, gfx_context_t *outgc)
{
ds_clonegc_output_t *output;
ds_clonegc_bitmap_t *cbm;
errno_t rc;
output = calloc(1, sizeof(ds_clonegc_output_t));
if (output == NULL)
return ENOMEM;
output->clonegc = cgc;
list_append(&output->loutputs, &cgc->outputs);
output->gc = outgc;
list_initialize(&output->obitmaps);
cbm = ds_clonegc_first_bitmap(cgc);
while (cbm != NULL) {
rc = ds_clonegc_bitmap_add_output(cbm, output);
if (rc != EOK)
goto error;
cbm = ds_clonegc_next_bitmap(cbm);
}
return EOK;
error:
list_remove(&output->loutputs);
free(output);
return rc;
}
gfx_context_t *ds_clonegc_get_ctx(ds_clonegc_t *cgc)
{
return cgc->gc;
}
errno_t ds_clonegc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
gfx_bitmap_alloc_t *alloc, void **rbm)
{
ds_clonegc_t *cgc = (ds_clonegc_t *)arg;
ds_clonegc_bitmap_t *cbm = NULL;
ds_clonegc_output_t *output;
gfx_bitmap_t *bitmap;
errno_t rc;
cbm = calloc(1, sizeof(ds_clonegc_bitmap_t));
if (cbm == NULL)
return ENOMEM;
list_initialize(&cbm->obitmaps);
cbm->clonegc = cgc;
cbm->params = *params;
output = ds_clonegc_first_output(cgc);
assert(output != NULL);
rc = gfx_bitmap_create(output->gc, params, alloc, &bitmap);
if (rc != EOK)
goto error;
rc = gfx_bitmap_get_alloc(bitmap, &cbm->alloc);
if (rc != EOK)
goto error;
rc = ds_clonegc_outbitmap_create(output, cbm, bitmap);
if (rc != EOK)
goto error;
bitmap = NULL;
output = ds_clonegc_next_output(output);
while (output != NULL) {
rc = ds_clonegc_bitmap_add_output(cbm, output);
if (rc != EOK)
goto error;
output = ds_clonegc_next_output(output);
}
list_append(&cbm->lbitmaps, &cgc->bitmaps);
*rbm = (void *)cbm;
return EOK;
error:
if (bitmap != NULL)
gfx_bitmap_destroy(bitmap);
if (cbm != NULL)
ds_clonegc_bitmap_destroy(cbm);
return rc;
}
static errno_t ds_clonegc_bitmap_destroy(void *bm)
{
ds_clonegc_bitmap_t *cbm = (ds_clonegc_bitmap_t *)bm;
ds_clonegc_outbitmap_t *outbm;
errno_t rc;
outbm = ds_clonegc_bitmap_first_obm(cbm);
while (outbm != NULL) {
rc = ds_clonegc_outbitmap_destroy(outbm);
if (rc != EOK)
return rc;
outbm = ds_clonegc_bitmap_first_obm(cbm);
}
list_remove(&cbm->lbitmaps);
free(cbm);
return EOK;
}
static errno_t ds_clonegc_bitmap_render(void *bm, gfx_rect_t *srect0,
gfx_coord2_t *offs0)
{
ds_clonegc_bitmap_t *cbm = (ds_clonegc_bitmap_t *)bm;
ds_clonegc_outbitmap_t *outbm;
errno_t rc;
outbm = ds_clonegc_bitmap_first_obm(cbm);
while (outbm != NULL) {
rc = gfx_bitmap_render(outbm->obitmap, srect0, offs0);
if (rc != EOK)
return rc;
outbm = ds_clonegc_bitmap_next_obm(outbm);
}
return EOK;
}
static errno_t ds_clonegc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
{
ds_clonegc_bitmap_t *cbm = (ds_clonegc_bitmap_t *)bm;
*alloc = cbm->alloc;
return EOK;
}
static ds_clonegc_output_t *ds_clonegc_first_output(ds_clonegc_t *cgc)
{
link_t *link;
link = list_first(&cgc->outputs);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_clonegc_output_t, loutputs);
}
static ds_clonegc_output_t *ds_clonegc_next_output(ds_clonegc_output_t *cur)
{
link_t *link;
link = list_next(&cur->loutputs, &cur->clonegc->outputs);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_clonegc_output_t, loutputs);
}
static ds_clonegc_bitmap_t *ds_clonegc_first_bitmap(ds_clonegc_t *cgc)
{
link_t *link;
link = list_first(&cgc->bitmaps);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_clonegc_bitmap_t, lbitmaps);
}
static ds_clonegc_bitmap_t *ds_clonegc_next_bitmap(ds_clonegc_bitmap_t *cur)
{
link_t *link;
link = list_next(&cur->lbitmaps, &cur->clonegc->bitmaps);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_clonegc_bitmap_t, lbitmaps);
}
static ds_clonegc_outbitmap_t *ds_clonegc_bitmap_first_obm(ds_clonegc_bitmap_t *cbm)
{
link_t *link;
link = list_first(&cbm->obitmaps);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_clonegc_outbitmap_t, lbbitmaps);
}
static ds_clonegc_outbitmap_t *ds_clonegc_bitmap_next_obm(ds_clonegc_outbitmap_t *cur)
{
link_t *link;
link = list_next(&cur->lbbitmaps, &cur->bitmap->obitmaps);
if (link == NULL)
return NULL;
return list_get_instance(link, ds_clonegc_outbitmap_t, lbbitmaps);
}
static errno_t ds_clonegc_outbitmap_create(ds_clonegc_output_t *output,
ds_clonegc_bitmap_t *cbm, gfx_bitmap_t *obitmap)
{
ds_clonegc_outbitmap_t *outbm;
outbm = calloc(1, sizeof(ds_clonegc_outbitmap_t));
if (outbm == NULL)
return ENOMEM;
outbm->output = output;
outbm->bitmap = cbm;
list_append(&outbm->lobitmaps, &output->obitmaps);
list_append(&outbm->lbbitmaps, &cbm->obitmaps);
outbm->obitmap = obitmap;
return EOK;
}
static errno_t ds_clonegc_outbitmap_destroy(ds_clonegc_outbitmap_t *outbm)
{
errno_t rc;
rc = gfx_bitmap_destroy(outbm->obitmap);
if (rc != EOK)
return rc;
list_remove(&outbm->lobitmaps);
list_remove(&outbm->lbbitmaps);
free(outbm);
return EOK;
}
static errno_t ds_clonegc_bitmap_add_output(ds_clonegc_bitmap_t *cbm,
ds_clonegc_output_t *output)
{
gfx_bitmap_t *obitmap = NULL;
errno_t rc;
rc = gfx_bitmap_create(output->gc, &cbm->params, &cbm->alloc, &obitmap);
if (rc != EOK)
goto error;
rc = ds_clonegc_outbitmap_create(output, cbm, obitmap);
if (rc != EOK)
goto error;
return EOK;
error:
if (obitmap != NULL)
gfx_bitmap_destroy(obitmap);
return rc;
}
HelenOS homepage, sources at GitHub