summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-09-26 11:59:03 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-10-04 17:22:09 +0200
commit9a048064e4803340cfe997dada9f09b00077a1f5 (patch)
tree4a8c3fdb1cb3f81fea44f21d7efddd92dfc547df /lib
parent3fa8d74abea368d70e49be5671ea1b135cef644d (diff)
downloadbarebox-9a048064e4803340cfe997dada9f09b00077a1f5.tar.gz
barebox-9a048064e4803340cfe997dada9f09b00077a1f5.tar.xz
graphic_utils: introduce common fb_open/close
To open, memmap, get the fb_info and if needed allocate the offscreen buffer Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/gui/bmp.c5
-rw-r--r--lib/gui/graphic_utils.c52
-rw-r--r--lib/gui/png.c8
3 files changed, 56 insertions, 9 deletions
diff --git a/lib/gui/bmp.c b/lib/gui/bmp.c
index 63902ef73..c88037568 100644
--- a/lib/gui/bmp.c
+++ b/lib/gui/bmp.c
@@ -37,7 +37,7 @@ void bmp_close(struct image *img)
static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
{
struct bmp_image *bmp = img->data;
- int bits_per_pixel, fbsize;
+ int bits_per_pixel;
void *adr, *buf;
char *image;
int width = s->width;
@@ -69,7 +69,6 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
buf = gui_screen_redering_buffer(sc);
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;
@@ -119,7 +118,7 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
printf("bmp: illegal bits per pixel value: %d\n", bits_per_pixel);
if (sc->offscreenbuf)
- memcpy(sc->fb, sc->offscreenbuf, fbsize);
+ memcpy(sc->fb, sc->offscreenbuf, sc->fbsize);
return img->height;
}
diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
index 06f811c6c..15a41094a 100644
--- a/lib/gui/graphic_utils.c
+++ b/lib/gui/graphic_utils.c
@@ -1,6 +1,11 @@
#include <common.h>
#include <fb.h>
#include <gui/graphic_utils.h>
+#include <linux/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <fs.h>
+#include <malloc.h>
static u32 get_pixel(struct fb_info *info, u32 color)
{
@@ -190,3 +195,50 @@ void rgba_blend(struct fb_info *info, struct image *img, void* buf, int height,
}
}
}
+
+int fb_open(const char * fbdev, struct screen *sc, bool offscreen)
+{
+ int ret;
+
+ sc->fd = open(fbdev, O_RDWR);
+ if (sc->fd < 0)
+ return sc->fd;
+
+ sc->fb = memmap(sc->fd, PROT_READ | PROT_WRITE);
+ if (sc->fb == (void *)-1) {
+ ret = -ENOMEM;
+ goto failed_memmap;
+ }
+
+ ret = ioctl(sc->fd, FBIOGET_SCREENINFO, &sc->info);
+ if (ret) {
+ goto failed_memmap;
+ }
+
+ sc->s.x = 0;
+ sc->s.y = 0;
+ sc->s.width = sc->info.xres;
+ sc->s.height = sc->info.yres;
+ sc->fbsize = sc->s.x * sc->s.x * (sc->info.bits_per_pixel >> 3);
+
+ if (offscreen) {
+ /* Don't fail if malloc fails, just continue rendering directly
+ * on the framebuffer
+ */
+ sc->offscreenbuf = malloc(sc->fbsize);
+ }
+
+ return sc->fd;
+
+failed_memmap:
+ sc->fb = NULL;
+ close(sc->fd);
+
+ return ret;
+}
+
+void fb_close(struct screen *sc)
+{
+ free(sc->offscreenbuf);
+ close(sc->fd);
+}
diff --git a/lib/gui/png.c b/lib/gui/png.c
index 3845d7e4b..36b95f6af 100644
--- a/lib/gui/png.c
+++ b/lib/gui/png.c
@@ -69,12 +69,8 @@ static int png_renderer(struct screen *sc, struct surface *s, struct image *img)
rgba_blend(&sc->info, img, buf, height, width, startx, starty, true);
- if (sc->offscreenbuf) {
- int fbsize;
-
- fbsize = sc->s.width * sc->s.height * (sc->info.bits_per_pixel >> 3);
- memcpy(sc->fb, sc->offscreenbuf, fbsize);
- }
+ if (sc->offscreenbuf)
+ memcpy(sc->fb, sc->offscreenbuf, sc->fbsize);
return img->height;
}