summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-04-23 22:48:01 +0100
committerVincent Sanders <vince@kyllikki.org>2015-04-23 22:50:16 +0100
commit1a22eb2b658215ccb1d5281a4b30a2055fe6b8f6 (patch)
treea3940423429033c3227d3ed96bd8a6abdde1150c
parent7e2f1094ce8d527c07e06dea164d7647d6605a4f (diff)
downloadnetsurf-1a22eb2b658215ccb1d5281a4b30a2055fe6b8f6.tar.gz
netsurf-1a22eb2b658215ccb1d5281a4b30a2055fe6b8f6.tar.bz2
Convert framebuffer to use bitmap render from thumbnail API
-rw-r--r--framebuffer/Makefile.target5
-rw-r--r--framebuffer/bitmap.c80
-rw-r--r--framebuffer/thumbnail.c97
3 files changed, 81 insertions, 101 deletions
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index d652c8a44..0431abf69 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -163,9 +163,8 @@ $(eval $(foreach V,$(filter FB_FONT_$(NETSURF_FB_FONTLIB)_%,$(.VARIABLES)),$(cal
# ----------------------------------------------------------------------------
# S_FRAMEBUFFER are sources purely for the framebuffer build
-S_FRAMEBUFFER := gui.c framebuffer.c schedule.c \
- thumbnail.c misc.c bitmap.c fetch.c findfile.c \
- localhistory.c clipboard.c
+S_FRAMEBUFFER := gui.c framebuffer.c schedule.c misc.c bitmap.c fetch.c \
+ findfile.c localhistory.c clipboard.c
S_FRAMEBUFFER_FBTK := fbtk.c event.c fill.c bitmap.c user.c window.c \
text.c scroll.c osk.c
diff --git a/framebuffer/bitmap.c b/framebuffer/bitmap.c
index 713cf840a..9f5b02524 100644
--- a/framebuffer/bitmap.c
+++ b/framebuffer/bitmap.c
@@ -26,10 +26,17 @@
#include <stdbool.h>
#include <assert.h>
#include <libnsfb.h>
+#include <libnsfb_plot.h>
-#include "image/bitmap.h"
#include "utils/log.h"
+#include "utils/utils.h"
+#include "image/bitmap.h"
+#include "desktop/plotters.h"
+#include "content/content.h"
+#include "framebuffer/gui.h"
+#include "framebuffer/fbtk.h"
+#include "framebuffer/framebuffer.h"
#include "framebuffer/bitmap.h"
/**
@@ -249,6 +256,76 @@ static size_t bitmap_get_bpp(void *bitmap)
return 4;
}
+/**
+ * Render content into a bitmap.
+ *
+ * \param bitmap the bitmap to draw to
+ * \param content content structure to render
+ * \return true on success and bitmap updated else false
+ */
+static nserror
+bitmap_render(struct bitmap *bitmap,
+ struct hlcache_handle *content)
+{
+ 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,
+ .background_images = true,
+ .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 NSERROR_NOMEM;
+ }
+
+ nsfb_set_geometry(bm, cwidth, cheight, NSFB_FMT_XBGR8888);
+
+ if (nsfb_init(bm) == -1) {
+ nsfb_free(bm);
+ return NSERROR_NOMEM;
+ }
+
+ current = framebuffer_set_surface(bm);
+
+ /* render the content into temporary surface */
+ content_scaled_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);
+
+ return NSERROR_OK;
+}
+
static struct gui_bitmap_table bitmap_table = {
.create = bitmap_create,
.destroy = bitmap_destroy,
@@ -262,6 +339,7 @@ static struct gui_bitmap_table bitmap_table = {
.get_bpp = bitmap_get_bpp,
.save = bitmap_save,
.modified = bitmap_modified,
+ .render = bitmap_render,
};
struct gui_bitmap_table *framebuffer_bitmap_table = &bitmap_table;
diff --git a/framebuffer/thumbnail.c b/framebuffer/thumbnail.c
deleted file mode 100644
index 24067fd2f..000000000
--- a/framebuffer/thumbnail.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include <stdbool.h>
-
-#include <libnsfb.h>
-#include <libnsfb_plot.h>
-
-#include "utils/log.h"
-#include "utils/utils.h"
-#include "desktop/plotters.h"
-#include "desktop/thumbnail.h"
-#include "content/urldb.h"
-#include "content/content.h"
-
-#include "framebuffer/gui.h"
-#include "framebuffer/fbtk.h"
-#include "framebuffer/framebuffer.h"
-
-bool
-thumbnail_create(struct hlcache_handle *content,
- struct bitmap *bitmap)
-{
- 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,
- .background_images = true,
- .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);
-
- return true;
-}