mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-16 09:12:44 +03:00
Convert framebuffer to use bitmap render from thumbnail API
This commit is contained in:
parent
7e2f1094ce
commit
1a22eb2b65
@ -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 are sources purely for the framebuffer build
|
||||||
S_FRAMEBUFFER := gui.c framebuffer.c schedule.c \
|
S_FRAMEBUFFER := gui.c framebuffer.c schedule.c misc.c bitmap.c fetch.c \
|
||||||
thumbnail.c misc.c bitmap.c fetch.c findfile.c \
|
findfile.c localhistory.c clipboard.c
|
||||||
localhistory.c clipboard.c
|
|
||||||
|
|
||||||
S_FRAMEBUFFER_FBTK := fbtk.c event.c fill.c bitmap.c user.c window.c \
|
S_FRAMEBUFFER_FBTK := fbtk.c event.c fill.c bitmap.c user.c window.c \
|
||||||
text.c scroll.c osk.c
|
text.c scroll.c osk.c
|
||||||
|
@ -26,10 +26,17 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libnsfb.h>
|
#include <libnsfb.h>
|
||||||
|
#include <libnsfb_plot.h>
|
||||||
|
|
||||||
#include "image/bitmap.h"
|
|
||||||
#include "utils/log.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"
|
#include "framebuffer/bitmap.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,6 +256,76 @@ static size_t bitmap_get_bpp(void *bitmap)
|
|||||||
return 4;
|
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 = {
|
static struct gui_bitmap_table bitmap_table = {
|
||||||
.create = bitmap_create,
|
.create = bitmap_create,
|
||||||
.destroy = bitmap_destroy,
|
.destroy = bitmap_destroy,
|
||||||
@ -262,6 +339,7 @@ static struct gui_bitmap_table bitmap_table = {
|
|||||||
.get_bpp = bitmap_get_bpp,
|
.get_bpp = bitmap_get_bpp,
|
||||||
.save = bitmap_save,
|
.save = bitmap_save,
|
||||||
.modified = bitmap_modified,
|
.modified = bitmap_modified,
|
||||||
|
.render = bitmap_render,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gui_bitmap_table *framebuffer_bitmap_table = &bitmap_table;
|
struct gui_bitmap_table *framebuffer_bitmap_table = &bitmap_table;
|
||||||
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user