summaryrefslogtreecommitdiffstats
path: root/lib/gui
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-09-26 11:59:02 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-10-04 17:22:09 +0200
commit3fa8d74abea368d70e49be5671ea1b135cef644d (patch)
tree7a7d06e04ff8caecc72812e5f9e4bf264667d561 /lib/gui
parent21a8ef55b0a2140a7ef7bd38869ff63592335861 (diff)
downloadbarebox-3fa8d74abea368d70e49be5671ea1b135cef644d.tar.gz
barebox-3fa8d74abea368d70e49be5671ea1b135cef644d.tar.xz
gui: introduce screen and surface to factorize and simplify code
Instead of passing hundreds of parameter, just pass the right structure. struct screen represent the screen with a without double buffering. struct surface represent the part of the screen we want to render. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/gui')
-rw-r--r--lib/gui/bmp.c50
-rw-r--r--lib/gui/image_renderer.c5
-rw-r--r--lib/gui/png.c34
3 files changed, 48 insertions, 41 deletions
diff --git a/lib/gui/bmp.c b/lib/gui/bmp.c
index 86591edfde..63902ef73c 100644
--- a/lib/gui/bmp.c
+++ b/lib/gui/bmp.c
@@ -34,38 +34,42 @@ void bmp_close(struct image *img)
free(img->data);
}
-static int bmp_renderer(struct fb_info *info, struct image *img, void* fb,
- int startx, int starty, void* offscreenbuf)
+static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
{
struct bmp_image *bmp = img->data;
- int width, height;
int bits_per_pixel, fbsize;
void *adr, *buf;
char *image;
- int xres, yres;
+ int width = s->width;
+ int height = s->height;
+ int startx = s->x;
+ int starty = s->y;
- xres = info->xres;
- yres = info->yres;
+ if (s->width < 0)
+ width = img->width;
+
+ if (s->height < 0)
+ height = img->height;
if (startx < 0) {
- startx = (xres - img->width) / 2;
+ startx = (sc->s.width - width) / 2;
if (startx < 0)
startx = 0;
}
if (starty < 0) {
- starty = (yres - img->height) / 2;
+ starty = (sc->s.height - height) / 2;
if (starty < 0)
starty = 0;
}
- width = min(img->width, xres - startx);
- height = min(img->height, yres - starty);
+ width = min(width, sc->s.width - startx);
+ height = min(height, sc->s.height - starty);
- bits_per_pixel = img->bits_per_pixel;
- fbsize = xres * yres * (info->bits_per_pixel >> 3);
+ buf = gui_screen_redering_buffer(sc);
- buf = offscreenbuf ? offscreenbuf : fb;
+ bits_per_pixel = img->bits_per_pixel;
+ fbsize = sc->s.width * sc->s.height * (sc->info.bits_per_pixel >> 3);
if (bits_per_pixel == 8) {
int x, y;
@@ -75,17 +79,17 @@ static int bmp_renderer(struct fb_info *info, struct image *img, void* fb,
image = (char *)bmp +
le32_to_cpu(bmp->header.data_offset);
image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3);
- adr = buf + ((y + starty) * xres + startx) *
- (info->bits_per_pixel >> 3);
+ adr = buf + ((y + starty) * sc->s.width + startx) *
+ (sc->info.bits_per_pixel >> 3);
for (x = 0; x < width; x++) {
int pixel;
pixel = *image;
- set_rgb_pixel(info, adr, color_table[pixel].red,
+ set_rgb_pixel(&sc->info, adr, color_table[pixel].red,
color_table[pixel].green,
color_table[pixel].blue);
- adr += info->bits_per_pixel >> 3;
+ adr += sc->info.bits_per_pixel >> 3;
image += bits_per_pixel >> 3;
}
@@ -97,16 +101,16 @@ static int bmp_renderer(struct fb_info *info, struct image *img, void* fb,
image = (char *)bmp +
le32_to_cpu(bmp->header.data_offset);
image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3);
- adr = buf + ((y + starty) * xres + startx) *
- (info->bits_per_pixel >> 3);
+ adr = buf + ((y + starty) * sc->s.width + startx) *
+ (sc->info.bits_per_pixel >> 3);
for (x = 0; x < width; x++) {
char *pixel;
pixel = image;
- set_rgb_pixel(info, adr, pixel[2], pixel[1],
+ set_rgb_pixel(&sc->info, adr, pixel[2], pixel[1],
pixel[0]);
- adr += info->bits_per_pixel >> 3;
+ adr += sc->info.bits_per_pixel >> 3;
image += bits_per_pixel >> 3;
}
@@ -114,8 +118,8 @@ static int bmp_renderer(struct fb_info *info, struct image *img, void* fb,
} else
printf("bmp: illegal bits per pixel value: %d\n", bits_per_pixel);
- if (offscreenbuf)
- memcpy(fb, offscreenbuf, fbsize);
+ if (sc->offscreenbuf)
+ memcpy(sc->fb, sc->offscreenbuf, fbsize);
return img->height;
}
diff --git a/lib/gui/image_renderer.c b/lib/gui/image_renderer.c
index 99e4335d03..41dc43b3c7 100644
--- a/lib/gui/image_renderer.c
+++ b/lib/gui/image_renderer.c
@@ -71,10 +71,9 @@ void image_renderer_close(struct image *img)
free(img);
}
-int image_renderer_image(struct fb_info *info, struct image *img, void* fb,
- int startx, int starty, void* offscreenbuf)
+int image_renderer_image(struct screen *sc, struct surface *s, struct image *img)
{
- return img->ir->renderer(info, img, fb, startx, starty, offscreenbuf);
+ return img->ir->renderer(sc, s, img);
}
int image_renderer_register(struct image_renderer *ir)
diff --git a/lib/gui/png.c b/lib/gui/png.c
index 1e9efd529d..3845d7e4be 100644
--- a/lib/gui/png.c
+++ b/lib/gui/png.c
@@ -36,40 +36,44 @@ void png_uncompress_exit(void)
}
}
-static int png_renderer(struct fb_info *info, struct image *img, void* fb,
- int startx, int starty, void* offscreenbuf)
+static int png_renderer(struct screen *sc, struct surface *s, struct image *img)
{
- int width, height;
void *buf;
- int xres, yres;
+ int width = s->width;
+ int height = s->height;
+ int startx = s->x;
+ int starty = s->y;
- xres = info->xres;
- yres = info->yres;
+ if (s->width < 0)
+ width = img->width;
+
+ if (s->height < 0)
+ height = img->height;
if (startx < 0) {
- startx = (xres - img->width) / 2;
+ startx = (sc->s.width - width) / 2;
if (startx < 0)
startx = 0;
}
if (starty < 0) {
- starty = (yres - img->height) / 2;
+ starty = (sc->s.height - height) / 2;
if (starty < 0)
starty = 0;
}
- width = min(img->width, xres - startx);
- height = min(img->height, yres - starty);
+ width = min(width, sc->s.width - startx);
+ height = min(height, sc->s.height - starty);
- buf = offscreenbuf ? offscreenbuf : fb;
+ buf = gui_screen_redering_buffer(sc);
- rgba_blend(info, img, buf, height, width, startx, starty, true);
+ rgba_blend(&sc->info, img, buf, height, width, startx, starty, true);
- if (offscreenbuf) {
+ if (sc->offscreenbuf) {
int fbsize;
- fbsize = xres * yres * (info->bits_per_pixel >> 3);
- memcpy(fb, offscreenbuf, fbsize);
+ fbsize = sc->s.width * sc->s.height * (sc->info.bits_per_pixel >> 3);
+ memcpy(sc->fb, sc->offscreenbuf, fbsize);
}
return img->height;