summaryrefslogtreecommitdiff
path: root/framebuffer/thumbnail.c
diff options
context:
space:
mode:
Diffstat (limited to 'framebuffer/thumbnail.c')
-rw-r--r--framebuffer/thumbnail.c70
1 files changed, 68 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
*/
+#include <stdbool.h>
+
+#include <libnsfb.h>
+#include <libnsfb_plot.h>
+
+#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);