diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-07-13 08:14:39 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-07-20 07:11:21 +0200 |
commit | cfec57d89808343bb6b043955e39411a0e29be5d (patch) | |
tree | df172524d9d5bef3d15e8c461bf395e90d17f635 /lib | |
parent | 772ab4f1722c5d166fe0677aa779e7b8628f0a79 (diff) | |
download | barebox-cfec57d89808343bb6b043955e39411a0e29be5d.tar.gz barebox-cfec57d89808343bb6b043955e39411a0e29be5d.tar.xz |
graphics_utils: Let fb_open allocate the screen
Allocate the screen dynamically in fb_open. This opens the way to create
a fb_create_screen function which takes a struct fb_info * instead of a
filename. This is suitable for the framebuffer console which already has
a struct fb_info *.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gui/bmp.c | 16 | ||||
-rw-r--r-- | lib/gui/graphic_utils.c | 78 | ||||
-rw-r--r-- | lib/gui/png.c | 2 |
3 files changed, 61 insertions, 35 deletions
diff --git a/lib/gui/bmp.c b/lib/gui/bmp.c index 892b759ee1..143aa28055 100644 --- a/lib/gui/bmp.c +++ b/lib/gui/bmp.c @@ -79,17 +79,17 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img) image = (char *)bmp + get_unaligned_le32(&bmp->header.data_offset); image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3); - adr = buf + (y + starty) * sc->info.line_length + - startx * (sc->info.bits_per_pixel >> 3); + adr = buf + (y + starty) * sc->info->line_length + + startx * (sc->info->bits_per_pixel >> 3); for (x = 0; x < width; x++) { int pixel; pixel = *image; - gu_set_rgb_pixel(&sc->info, adr, color_table[pixel].red, + gu_set_rgb_pixel(sc->info, adr, color_table[pixel].red, color_table[pixel].green, color_table[pixel].blue); - adr += sc->info.bits_per_pixel >> 3; + adr += sc->info->bits_per_pixel >> 3; image += bits_per_pixel >> 3; } @@ -101,16 +101,16 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img) image = (char *)bmp + get_unaligned_le32(&bmp->header.data_offset); image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3); - adr = buf + (y + starty) * sc->info.line_length + - startx * (sc->info.bits_per_pixel >> 3); + adr = buf + (y + starty) * sc->info->line_length + + startx * (sc->info->bits_per_pixel >> 3); for (x = 0; x < width; x++) { char *pixel; pixel = image; - gu_set_rgb_pixel(&sc->info, adr, pixel[2], pixel[1], + gu_set_rgb_pixel(sc->info, adr, pixel[2], pixel[1], pixel[0]); - adr += sc->info.bits_per_pixel >> 3; + adr += sc->info->bits_per_pixel >> 3; image += bits_per_pixel >> 3; } diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c index 7302611cb4..47003a0837 100644 --- a/lib/gui/graphic_utils.c +++ b/lib/gui/graphic_utils.c @@ -245,51 +245,77 @@ void gu_rgba_blend(struct fb_info *info, struct image *img, void* buf, int heigh } } -int fb_open(const char * fbdev, struct screen *sc, bool offscreen) +struct screen *fb_create_screen(struct fb_info *info, bool offscreen) { - int ret; + struct screen *sc; - 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 = xzalloc(sizeof(*sc)); sc->s.x = 0; sc->s.y = 0; - sc->s.width = sc->info.xres; - sc->s.height = sc->info.yres; - sc->fbsize = sc->info.line_length * sc->s.height; + sc->s.width = info->xres; + sc->s.height = info->yres; + sc->fbsize = info->line_length * sc->s.height; + sc->fb = info->screen_base; if (offscreen) { - /* Don't fail if malloc fails, just continue rendering directly + /* + * Don't fail if malloc fails, just continue rendering directly * on the framebuffer */ sc->offscreenbuf = malloc(sc->fbsize); } - return sc->fd; + return sc; +} -failed_memmap: - sc->fb = NULL; - close(sc->fd); +struct screen *fb_open(const char * fbdev, bool offscreen) +{ + int fd, ret; + struct fb_info *info; + struct screen *sc; + + fd = open(fbdev, O_RDWR); + if (fd < 0) + return ERR_PTR(fd); + + info = xzalloc(sizeof(*info)); - return ret; + ret = ioctl(fd, FBIOGET_SCREENINFO, info); + if (ret) { + goto failed_screeninfo; + } + + sc = fb_create_screen(info, offscreen); + if (IS_ERR(sc)) { + ret = PTR_ERR(sc); + goto failed_create; + } + + sc->fd = fd; + sc->info = info; + + return sc; + +failed_create: + free(sc->offscreenbuf); + free(sc); +failed_screeninfo: + close(fd); + + return ERR_PTR(ret); } void fb_close(struct screen *sc) { free(sc->offscreenbuf); - close(sc->fd); + + if (sc->fd > 0) { + close(sc->fd); + free(sc->info); + } + + free(sc); } void gu_screen_blit(struct screen *sc) diff --git a/lib/gui/png.c b/lib/gui/png.c index e72786e041..6bf997c29a 100644 --- a/lib/gui/png.c +++ b/lib/gui/png.c @@ -67,7 +67,7 @@ static int png_renderer(struct screen *sc, struct surface *s, struct image *img) buf = gui_screen_render_buffer(sc); - gu_rgba_blend(&sc->info, img, buf, height, width, startx, starty, true); + gu_rgba_blend(sc->info, img, buf, height, width, startx, starty, true); return img->height; } |