From 820312eb35e6fa4f0930a343e8d418c4e2011755 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 21 Nov 2011 08:45:08 +0000 Subject: Update for modified libnsfb API Make thumbnailing work svn path=/trunk/netsurf/; revision=13159 --- framebuffer/Makefile.target | 2 +- framebuffer/bitmap.c | 154 +++++++++++++++++++++++--------------------- framebuffer/bitmap.h | 33 ---------- framebuffer/convert_image.c | 7 +- framebuffer/fbtk.h | 18 +++++- framebuffer/fbtk/bitmap.c | 7 +- framebuffer/fbtk/event.c | 1 - framebuffer/fbtk/fbtk.c | 3 +- framebuffer/fbtk/osk.c | 1 - framebuffer/fbtk/scroll.c | 1 - framebuffer/fbtk/user.c | 2 +- framebuffer/fbtk/widget.h | 2 +- framebuffer/framebuffer.c | 109 ++++++++++++++++++++----------- framebuffer/framebuffer.h | 8 ++- framebuffer/gui.c | 11 ++-- framebuffer/image_data.h | 68 +++++++++---------- framebuffer/localhistory.c | 1 - framebuffer/thumbnail.c | 70 +++++++++++++++++++- 18 files changed, 294 insertions(+), 204 deletions(-) delete mode 100644 framebuffer/bitmap.h (limited to 'framebuffer') diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target index b4191daaa..425faacaf 100644 --- a/framebuffer/Makefile.target +++ b/framebuffer/Makefile.target @@ -74,7 +74,7 @@ endif # We make convert_image depend on fb_bitmap.h so that if we change # that header, we get new images built just in case. -$(TOOLROOT)/convert_image: $(TOOLROOT)/created framebuffer/convert_image.c framebuffer/bitmap.h +$(TOOLROOT)/convert_image: $(TOOLROOT)/created framebuffer/convert_image.c framebuffer/fbtk.h $(VQ)echo " HOST CC: $@" $(Q)$(HOST_CC) -o $@ framebuffer/convert_image.c -lpng diff --git a/framebuffer/bitmap.c b/framebuffer/bitmap.c index 4d4821686..491ee1594 100644 --- a/framebuffer/bitmap.c +++ b/framebuffer/bitmap.c @@ -18,11 +18,12 @@ #include #include +#include +#include -#include "assert.h" -#include "image/bitmap.h" -#include "framebuffer/bitmap.h" +#include +#include "image/bitmap.h" #include "utils/log.h" /** @@ -36,26 +37,29 @@ void *bitmap_create(int width, int height, unsigned int state) { - struct bitmap *bitmap; + nsfb_t *bm; LOG(("width %d, height %d, state %u",width,height,state)); - bitmap = calloc(1 , sizeof(struct bitmap)); - if (bitmap) { - bitmap->pixdata = calloc(4, width * height); - if (bitmap->pixdata != NULL) { - bitmap->width = width; - bitmap->height = height; - bitmap->opaque = (state & BITMAP_OPAQUE) != 0; - } else { - free(bitmap); - bitmap=NULL; - } - } + bm = nsfb_new(NSFB_SURFACE_RAM); + if (bm == NULL) { + return NULL; + } + + if ((state & BITMAP_OPAQUE) == 0) { + nsfb_set_geometry(bm, width, height, NSFB_FMT_ABGR8888); + } else { + nsfb_set_geometry(bm, width, height, NSFB_FMT_XBGR8888); + } - LOG(("bitmap %p", bitmap)); + if (nsfb_init(bm) == -1) { + nsfb_free(bm); + return NULL; + } - return bitmap; + LOG(("bitmap %p", bm)); + + return bm; } @@ -71,14 +75,14 @@ void *bitmap_create(int width, int height, unsigned int state) unsigned char *bitmap_get_buffer(void *bitmap) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; + unsigned char *bmpptr; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return NULL; - } - - return bm->pixdata; + assert(bm != NULL); + + nsfb_get_buffer(bm, &bmpptr, NULL); + + return bmpptr; } @@ -91,14 +95,14 @@ unsigned char *bitmap_get_buffer(void *bitmap) size_t bitmap_get_rowstride(void *bitmap) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; + int bmpstride; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return 0; - } + assert(bm != NULL); + + nsfb_get_buffer(bm, NULL, &bmpstride); - return (bm->width) * 4; + return bmpstride; } @@ -110,15 +114,11 @@ size_t bitmap_get_rowstride(void *bitmap) void bitmap_destroy(void *bitmap) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return; - } - - free(bm->pixdata); - free(bm); + assert(bm != NULL); + + nsfb_free(bm); } @@ -158,22 +158,24 @@ void bitmap_set_suspendable(void *bitmap, void *private_word, } /** - * Sets whether a bitmap should be plotted opaque + * Sets wether a bitmap should be plotted opaque * * \param bitmap a bitmap, as returned by bitmap_create() * \param opaque whether the bitmap should be plotted opaque */ void bitmap_set_opaque(void *bitmap, bool opaque) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return; - } + assert(bm != NULL); LOG(("setting bitmap %p to %s", bm, opaque?"opaque":"transparent")); - bm->opaque = opaque; + + if (opaque) { + nsfb_set_geometry(bm, 0, 0, NSFB_FMT_XBGR8888); + } else { + nsfb_set_geometry(bm, 0, 0, NSFB_FMT_ABGR8888); + } } @@ -186,17 +188,21 @@ void bitmap_set_opaque(void *bitmap, bool opaque) bool bitmap_test_opaque(void *bitmap) { int tst; - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; + unsigned char *bmpptr; + int width; + int height; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return false; - } + assert(bm != NULL); + + nsfb_get_buffer(bm, &bmpptr, NULL); - tst = bm->width * bm->height; + nsfb_get_geometry(bm, &width, &height, NULL); + + tst = width * height; while (tst-- > 0) { - if (bm->pixdata[(tst << 2) + 3] != 0xff) { + if (bmpptr[(tst << 2) + 3] != 0xff) { LOG(("bitmap %p has transparency",bm)); return false; } @@ -207,46 +213,50 @@ bool bitmap_test_opaque(void *bitmap) /** - * Gets whether a bitmap should be plotted opaque + * Gets weather a bitmap should be plotted opaque * * \param bitmap a bitmap, as returned by bitmap_create() */ bool bitmap_get_opaque(void *bitmap) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; + enum nsfb_format_e format; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return false; - } + assert(bm != NULL); + + nsfb_get_geometry(bm, NULL, NULL, &format); - return bm->opaque; + if (format == NSFB_FMT_ABGR8888) + return false; + + return true; } int bitmap_get_width(void *bitmap) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; + int width; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return 0; - } + assert(bm != NULL); - return(bm->width); + nsfb_get_geometry(bm, &width, NULL, NULL); + + return(width); } int bitmap_get_height(void *bitmap) { - struct bitmap *bm = bitmap; + nsfb_t *bm = bitmap; + int height; - if (bitmap == NULL) { - LOG(("NULL bitmap!")); - return 0; - } + assert(bm != NULL); + + nsfb_get_geometry(bm, NULL, &height, NULL); - return(bm->height); + return(height); } +/* get bytes per pixel */ size_t bitmap_get_bpp(void *bitmap) { return 4; diff --git a/framebuffer/bitmap.h b/framebuffer/bitmap.h deleted file mode 100644 index 9a75b0b13..000000000 --- a/framebuffer/bitmap.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2008 Vincent Sanders - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef FRAMEBUFFER_BITMAP_H -#define FRAMEBUFFER_BITMAP_H - -struct bitmap { - int width; - int height; - uint8_t *pixdata; - bool opaque; - - /* The following two are only used for cursors */ - int hot_x; - int hot_y; -}; - -#endif diff --git a/framebuffer/convert_image.c b/framebuffer/convert_image.c index f601aaa54..bf47a3515 100644 --- a/framebuffer/convert_image.c +++ b/framebuffer/convert_image.c @@ -177,7 +177,10 @@ main(int argc, char **argv) fprintf(f, "#include \n\n"); fprintf(f, "#include \n\n"); fprintf(f, "#include \n\n"); - fprintf(f, "#include \"framebuffer/bitmap.h\"\n\n"); + fprintf(f, "#include \n\n"); + fprintf(f, "#include \"desktop/plot_style.h\"\n"); + fprintf(f, "#include \"framebuffer/gui.h\"\n"); + fprintf(f, "#include \"framebuffer/fbtk.h\"\n\n"); fprintf(f, "static uint8_t %s_pixdata[] = {\n", argv[3]); for (y = 0; y < HEIGHT; ++y) { @@ -197,7 +200,7 @@ main(int argc, char **argv) } fprintf(f, "};\n\n"); - fprintf(f, "struct bitmap %s = {\n", argv[3]); + fprintf(f, "struct fbtk_bitmap %s = {\n", argv[3]); fprintf(f, "\t.width\t\t= %d,\n", WIDTH); fprintf(f, "\t.height\t\t= %d,\n", HEIGHT); fprintf(f, "\t.hot_x\t\t= %d,\n", HOT_X); diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h index 1d682d0c4..e58795742 100644 --- a/framebuffer/fbtk.h +++ b/framebuffer/fbtk.h @@ -61,6 +61,18 @@ typedef struct fbtk_callback_info { fbtk_widget_t *widget; } fbtk_callback_info; +/* structure for framebuffer toolkit bitmaps */ +struct fbtk_bitmap { + int width; + int height; + uint8_t *pixdata; + bool opaque; + + /* The following two are only used for cursors */ + int hot_x; + int hot_y; +}; + typedef int (*fbtk_callback)(fbtk_widget_t *widget, fbtk_callback_info *cbi); /* enter pressed on writable icon */ @@ -349,9 +361,9 @@ void *fbtk_get_userpw(fbtk_widget_t *widget); * @param window The window to add the bitmap widget to. * @return new widget handle or NULL on error. */ -fbtk_widget_t *fbtk_create_bitmap(fbtk_widget_t *window, int x, int y, int width, int height, colour c,struct bitmap *image); +fbtk_widget_t *fbtk_create_bitmap(fbtk_widget_t *window, int x, int y, int width, int height, colour c,struct fbtk_bitmap *image); -void fbtk_set_bitmap(fbtk_widget_t *widget, struct bitmap *image); +void fbtk_set_bitmap(fbtk_widget_t *widget, struct fbtk_bitmap *image); /** Create a button widget. * @@ -361,7 +373,7 @@ void fbtk_set_bitmap(fbtk_widget_t *widget, struct bitmap *image); * @param window The window to add the button widget to. * @return new widget handle or NULL on error. */ -fbtk_widget_t *fbtk_create_button(fbtk_widget_t *window, int x, int y, int width, int height, colour c, struct bitmap *image, fbtk_callback click, void *pw); +fbtk_widget_t *fbtk_create_button(fbtk_widget_t *window, int x, int y, int width, int height, colour c, struct fbtk_bitmap *image, fbtk_callback click, void *pw); diff --git a/framebuffer/fbtk/bitmap.c b/framebuffer/fbtk/bitmap.c index 052d629b8..1f147be00 100644 --- a/framebuffer/fbtk/bitmap.c +++ b/framebuffer/fbtk/bitmap.c @@ -28,7 +28,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" -#include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" #include "widget.h" @@ -70,7 +69,7 @@ fb_redraw_bitmap(fbtk_widget_t *widget, fbtk_callback_info *cbi) /* exported function documented in fbtk.h */ void -fbtk_set_bitmap(fbtk_widget_t *widget, struct bitmap *image) +fbtk_set_bitmap(fbtk_widget_t *widget, struct fbtk_bitmap *image) { if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_BITMAP)) return; @@ -88,7 +87,7 @@ fbtk_create_bitmap(fbtk_widget_t *parent, int width, int height, colour c, - struct bitmap *image) + struct fbtk_bitmap *image) { fbtk_widget_t *neww; @@ -111,7 +110,7 @@ fbtk_create_button(fbtk_widget_t *parent, int width, int height, colour c, - struct bitmap *image, + struct fbtk_bitmap *image, fbtk_callback click, void *pw) { diff --git a/framebuffer/fbtk/event.c b/framebuffer/fbtk/event.c index d108af193..051afb1f6 100644 --- a/framebuffer/fbtk/event.c +++ b/framebuffer/fbtk/event.c @@ -37,7 +37,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" -#include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" #include "widget.h" diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c index f38f6adda..db298ebdc 100644 --- a/framebuffer/fbtk/fbtk.c +++ b/framebuffer/fbtk/fbtk.c @@ -38,7 +38,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" -#include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" #include "widget.h" @@ -337,7 +336,7 @@ int fbtk_set_ptr(fbtk_widget_t *widget, fbtk_callback_info *cbi) { fbtk_widget_t *root = fbtk_get_root_widget(widget); - struct bitmap *bm = cbi->context; + struct fbtk_bitmap *bm = cbi->context; nsfb_cursor_set(root->u.root.fb, (nsfb_colour_t *)bm->pixdata, diff --git a/framebuffer/fbtk/osk.c b/framebuffer/fbtk/osk.c index 8e6ee5185..02c9e4510 100644 --- a/framebuffer/fbtk/osk.c +++ b/framebuffer/fbtk/osk.c @@ -31,7 +31,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" -#include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" #include "widget.h" diff --git a/framebuffer/fbtk/scroll.c b/framebuffer/fbtk/scroll.c index 356fd11c7..0434f6d09 100644 --- a/framebuffer/fbtk/scroll.c +++ b/framebuffer/fbtk/scroll.c @@ -30,7 +30,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" -#include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" #include "widget.h" diff --git a/framebuffer/fbtk/user.c b/framebuffer/fbtk/user.c index 7a06a69a8..5be0f380f 100644 --- a/framebuffer/fbtk/user.c +++ b/framebuffer/fbtk/user.c @@ -19,7 +19,7 @@ */ #include - +#include #include #include "desktop/plotters.h" diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h index 75a2a646d..084a44047 100644 --- a/framebuffer/fbtk/widget.h +++ b/framebuffer/fbtk/widget.h @@ -165,7 +165,7 @@ struct fbtk_widget_s { /* bitmap */ struct { - struct bitmap *bitmap; + struct fbtk_bitmap *bitmap; } bitmap; /* text */ diff --git a/framebuffer/framebuffer.c b/framebuffer/framebuffer.c index 218a912e7..9195398cf 100644 --- a/framebuffer/framebuffer.c +++ b/framebuffer/framebuffer.c @@ -30,11 +30,11 @@ #include "utils/log.h" #include "desktop/browser.h" +#include "image/bitmap.h" #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" #include "framebuffer/framebuffer.h" -#include "framebuffer/bitmap.h" #include "framebuffer/font.h" /* netsurf framebuffer library handle */ @@ -175,8 +175,10 @@ framebuffer_plot_bitmap(int x, int y, nsfb_bbox_t clipbox; bool repeat_x = (flags & BITMAPF_REPEAT_X); bool repeat_y = (flags & BITMAPF_REPEAT_Y); - - nsfb_plot_get_clip(nsfb, &clipbox); + int bmwidth; + int bmheight; + unsigned char *bmptr; + nsfb_t *bm = (nsfb_t *)bitmap; /* x and y define coordinate of top left of of the initial explicitly * placed tile. The width and height are the image scaling and the @@ -191,26 +193,19 @@ framebuffer_plot_bitmap(int x, int y, loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; - if ((bitmap->width == 1) && (bitmap->height == 1)) { - if ((*(nsfb_colour_t *)bitmap->pixdata & 0xff000000) == 0) { - return true; - } - return nsfb_plot_rectangle_fill(nsfb, &loc, *(nsfb_colour_t *)bitmap->pixdata); - - } else { - return nsfb_plot_bitmap(nsfb, &loc, - (nsfb_colour_t *)bitmap->pixdata, - bitmap->width, bitmap->height, - bitmap->width, !bitmap->opaque); - } + return nsfb_plot_copy(bm, NULL, nsfb, &loc); } + nsfb_plot_get_clip(nsfb, &clipbox); + nsfb_get_geometry(bm, &bmwidth, &bmheight, NULL); + nsfb_get_buffer(bm, &bmptr, NULL); + /* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill * of the area. Can only be done when image is fully opaque. */ - if ((bitmap->width == 1) && (bitmap->height == 1)) { - if ((*(nsfb_colour_t *)bitmap->pixdata & 0xff000000) != 0) { + if ((bmwidth == 1) && (bmheight == 1)) { + if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) { return nsfb_plot_rectangle_fill(nsfb, &clipbox, - *(nsfb_colour_t *)bitmap->pixdata); + *(nsfb_colour_t *)bmptr); } } @@ -218,11 +213,11 @@ framebuffer_plot_bitmap(int x, int y, * a flat fill of the area. Can only be done when image is fully * opaque. */ if ((width == 1) && (height == 1)) { - if (bitmap->opaque) { + if (bitmap_get_opaque(bm)) { /** TODO: Currently using top left pixel. Maybe centre * pixel or average value would be better. */ return nsfb_plot_rectangle_fill(nsfb, &clipbox, - *(nsfb_colour_t *)bitmap->pixdata); + *(nsfb_colour_t *)bmptr); } } @@ -243,10 +238,8 @@ framebuffer_plot_bitmap(int x, int y, loc.x1 = loc.x0 + width; loc.y1 = loc.y0 + height; - nsfb_plot_bitmap(nsfb, &loc, - (nsfb_colour_t *)bitmap->pixdata, - bitmap->width, bitmap->height, - bitmap->width, !bitmap->opaque); + nsfb_plot_copy(bm, NULL, nsfb, &loc); + if (!repeat_y) break; } @@ -359,31 +352,63 @@ const struct plotter_table fb_plotters = { nsfb_t * framebuffer_initialise(const char *fename, int width, int height, int bpp) { - enum nsfb_frontend_e fetype; + enum nsfb_type_e fbtype; + enum nsfb_format_e fbfmt; + + /* bpp is a proxy for the framebuffer format */ + switch (bpp) { + case 32: + fbfmt = NSFB_FMT_XRGB8888; + break; + + case 24: + fbfmt = NSFB_FMT_RGB888; + break; + + case 16: + fbfmt = NSFB_FMT_RGB565; + break; + + case 8: + fbfmt = NSFB_FMT_I8; + break; + + case 4: + fbfmt = NSFB_FMT_I4; + break; + + case 1: + fbfmt = NSFB_FMT_I1; + break; + + default: + LOG(("Bad bits per pixel (%d)\n", bpp)); + return NULL; + } - fetype = nsfb_frontend_from_name(fename); - if (fetype == NSFB_FRONTEND_NONE) { - LOG(("The %s frontend is not available from libnsfb\n", fename)); + fbtype = nsfb_type_from_name(fename); + if (fbtype == NSFB_SURFACE_NONE) { + LOG(("The %s surface is not available from libnsfb\n", fename)); return NULL; } - nsfb = nsfb_init(fetype); + nsfb = nsfb_new(fbtype); if (nsfb == NULL) { - LOG(("Unable to initialise nsfb with %s frontend\n", fename)); + LOG(("Unable to create %s fb surface\n", fename)); return NULL; } - if (nsfb_set_geometry(nsfb, width, height, bpp) == -1) { - LOG(("Unable to set geometry\n")); - nsfb_finalise(nsfb); + if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) { + LOG(("Unable to set surface geometry\n")); + nsfb_free(nsfb); return NULL; } nsfb_cursor_init(nsfb); - if (nsfb_init_frontend(nsfb) == -1) { - LOG(("Unable to initialise nsfb frontend\n")); - nsfb_finalise(nsfb); + if (nsfb_init(nsfb) == -1) { + LOG(("Unable to initialise nsfb surface\n")); + nsfb_free(nsfb); return NULL; } @@ -394,11 +419,19 @@ framebuffer_initialise(const char *fename, int width, int height, int bpp) void framebuffer_finalise(void) { - nsfb_finalise(nsfb); + nsfb_free(nsfb); } bool -framebuffer_set_cursor(struct bitmap *bm) +framebuffer_set_cursor(struct fbtk_bitmap *bm) { return nsfb_cursor_set(nsfb, (nsfb_colour_t *)bm->pixdata, bm->width, bm->height, bm->width); } + +nsfb_t *framebuffer_set_surface(nsfb_t *new_nsfb) +{ + nsfb_t *old_nsfb; + old_nsfb = nsfb; + nsfb = new_nsfb; + return old_nsfb; +} diff --git a/framebuffer/framebuffer.h b/framebuffer/framebuffer.h index aec6a689f..0e46cb1f5 100644 --- a/framebuffer/framebuffer.h +++ b/framebuffer/framebuffer.h @@ -4,4 +4,10 @@ extern const struct plotter_table fb_plotters; nsfb_t *framebuffer_initialise(const char *fename, int width, int height, int bpp); void framebuffer_finalise(void); -bool framebuffer_set_cursor(struct bitmap *bm); +bool framebuffer_set_cursor(struct fbtk_bitmap *bm); + +/** Set framebuffer surface to render into + * + * @return return old surface + */ +nsfb_t *framebuffer_set_surface(nsfb_t *new_nsfb); diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 0c749bb65..5feae75f3 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -49,7 +49,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" #include "framebuffer/framebuffer.h" -#include "framebuffer/bitmap.h" #include "framebuffer/schedule.h" #include "framebuffer/findfile.h" #include "framebuffer/image_data.h" @@ -222,7 +221,7 @@ fb_pan(fbtk_widget_t *widget, dstbox.y1 = dstbox.y0 + height + bwidget->pany; /* move part that remains visible up */ - nsfb_plot_copy(nsfb, &srcbox, &dstbox); + nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox); /* redraw newly exposed area */ bwidget->scrolly += bwidget->pany; @@ -242,7 +241,7 @@ fb_pan(fbtk_widget_t *widget, dstbox.y1 = dstbox.y0 + height - bwidget->pany; /* move part that remains visible down */ - nsfb_plot_copy(nsfb, &srcbox, &dstbox); + nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox); /* redraw newly exposed area */ bwidget->scrolly += bwidget->pany; @@ -262,7 +261,7 @@ fb_pan(fbtk_widget_t *widget, dstbox.y1 = dstbox.y0 + height; /* move part that remains visible left */ - nsfb_plot_copy(nsfb, &srcbox, &dstbox); + nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox); /* redraw newly exposed area */ bwidget->scrollx += bwidget->panx; @@ -282,7 +281,7 @@ fb_pan(fbtk_widget_t *widget, dstbox.y1 = dstbox.y0 + height; /* move part that remains visible right */ - nsfb_plot_copy(nsfb, &srcbox, &dstbox); + nsfb_plot_copy(nsfb, &srcbox, nsfb, &dstbox); /* redraw newly exposed area */ bwidget->scrollx += bwidget->panx; @@ -1391,7 +1390,7 @@ static void throbber_advance(void *pw) { struct gui_window *g = pw; - struct bitmap *image; + struct fbtk_bitmap *image; switch (g->throbber_index) { case 0: diff --git a/framebuffer/image_data.h b/framebuffer/image_data.h index 42c9900fd..5ebac91ed 100644 --- a/framebuffer/image_data.h +++ b/framebuffer/image_data.h @@ -19,39 +19,39 @@ #ifndef FB_IMAGE_DATA #define FB_IMAGE_DATA -#include "framebuffer/bitmap.h" - -extern struct bitmap left_arrow; -extern struct bitmap right_arrow; -extern struct bitmap reload; -extern struct bitmap stop_image; -extern struct bitmap history_image; - -extern struct bitmap left_arrow_g; -extern struct bitmap right_arrow_g; -extern struct bitmap reload_g; -extern struct bitmap stop_image_g; -extern struct bitmap history_image_g; - -extern struct bitmap scrolll; -extern struct bitmap scrollr; -extern struct bitmap scrollu; -extern struct bitmap scrolld; - -extern struct bitmap pointer_image; -extern struct bitmap hand_image; -extern struct bitmap caret_image; -extern struct bitmap menu_image; -extern struct bitmap progress_image; - -extern struct bitmap throbber0; -extern struct bitmap throbber1; -extern struct bitmap throbber2; -extern struct bitmap throbber3; -extern struct bitmap throbber4; -extern struct bitmap throbber5; -extern struct bitmap throbber6; -extern struct bitmap throbber7; -extern struct bitmap throbber8; +#include "framebuffer/fbtk.h" + +extern struct fbtk_bitmap left_arrow; +extern struct fbtk_bitmap right_arrow; +extern struct fbtk_bitmap reload; +extern struct fbtk_bitmap stop_image; +extern struct fbtk_bitmap history_image; + +extern struct fbtk_bitmap left_arrow_g; +extern struct fbtk_bitmap right_arrow_g; +extern struct fbtk_bitmap reload_g; +extern struct fbtk_bitmap stop_image_g; +extern struct fbtk_bitmap history_image_g; + +extern struct fbtk_bitmap scrolll; +extern struct fbtk_bitmap scrollr; +extern struct fbtk_bitmap scrollu; +extern struct fbtk_bitmap scrolld; + +extern struct fbtk_bitmap pointer_image; +extern struct fbtk_bitmap hand_image; +extern struct fbtk_bitmap caret_image; +extern struct fbtk_bitmap menu_image; +extern struct fbtk_bitmap progress_image; + +extern struct fbtk_bitmap throbber0; +extern struct fbtk_bitmap throbber1; +extern struct fbtk_bitmap throbber2; +extern struct fbtk_bitmap throbber3; +extern struct fbtk_bitmap throbber4; +extern struct fbtk_bitmap throbber5; +extern struct fbtk_bitmap throbber6; +extern struct fbtk_bitmap throbber7; +extern struct fbtk_bitmap throbber8; #endif /* FB_IMAGE_DATA */ diff --git a/framebuffer/localhistory.c b/framebuffer/localhistory.c index 78c1a8d90..6f47ca5b2 100644 --- a/framebuffer/localhistory.c +++ b/framebuffer/localhistory.c @@ -45,7 +45,6 @@ #include "framebuffer/gui.h" #include "framebuffer/fbtk.h" #include "framebuffer/framebuffer.h" -#include "framebuffer/bitmap.h" #include "framebuffer/schedule.h" #include "framebuffer/findfile.h" #include "framebuffer/image_data.h" diff --git a/framebuffer/thumbnail.c b/framebuffer/thumbnail.c index 50b9ba932..1a3e2784b 100644 --- a/framebuffer/thumbnail.c +++ b/framebuffer/thumbnail.c @@ -16,14 +16,80 @@ * along with this program. If not, see . */ +#include + +#include +#include + +#include "utils/log.h" #include "desktop/thumbnail.h" #include "content/urldb.h" -bool -thumbnail_create(struct hlcache_handle *content, +#include "framebuffer/gui.h" +#include "framebuffer/fbtk.h" +#include "framebuffer/framebuffer.h" + +bool +thumbnail_create(struct hlcache_handle *content, struct bitmap *bitmap, const char *url) { + nsfb_t *tbm = (nsfb_t *)bitmap; /* target bitmap */ + nsfb_t *bm; /* temporary bitmap */ + nsfb_t *current; /* current main fb */ + int width, height; /* target bitmap width height */ + int cwidth, cheight;/* content width /height */ + nsfb_bbox_t loc; + + struct redraw_context ctx = { + .interactive = false, + .plot = &fb_plotters + }; + + + nsfb_get_geometry(tbm, &width, &height, NULL); + + LOG(("width %d, height %d", width, height)); + + /* Calculate size of buffer to render the content into */ + /* We get the width from the content width, unless it exceeds 1024, + * in which case we use 1024. This means we never create excessively + * large render buffers for huge contents, which would eat memory and + * cripple performance. */ + cwidth = min(content_get_width(content), 1024); + /* The height is set in proportion with the width, according to the + * aspect ratio of the required thumbnail. */ + cheight = ((cwidth * height) + (width / 2)) / width; + + /* create temporary surface */ + bm = nsfb_new(NSFB_SURFACE_RAM); + if (bm == NULL) { + return false; + } + + nsfb_set_geometry(bm, cwidth, cheight, NSFB_FMT_XBGR8888); + + if (nsfb_init(bm) == -1) { + nsfb_free(bm); + return false; + } + + current = framebuffer_set_surface(bm); + + /* render the content into temporary surface */ + thumbnail_redraw(content, cwidth, cheight, &ctx); + + framebuffer_set_surface(current); + + loc.x0 = 0; + loc.y0 = 0; + loc.x1 = width; + loc.y1 = height; + + nsfb_plot_copy(bm, NULL, tbm, &loc); + + nsfb_free(bm); + /* register the thumbnail with the URL */ if (url != NULL) urldb_set_thumbnail(url, bitmap); -- cgit v1.2.3