Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include <stdbool.h>
  20.  
  21. #include <libnsfb.h>
  22. #include <libnsfb_plot.h>
  23.  
  24. #include "utils/log.h"
  25. #include "desktop/thumbnail.h"
  26. #include "content/urldb.h"
  27.  
  28. #include "framebuffer/gui.h"
  29. #include "framebuffer/fbtk.h"
  30. #include "framebuffer/framebuffer.h"
  31.  
  32. bool
  33. thumbnail_create(struct hlcache_handle *content,
  34.                  struct bitmap *bitmap,
  35.                  nsurl *url)
  36. {
  37.         nsfb_t *tbm = (nsfb_t *)bitmap; /* target bitmap */
  38.         nsfb_t *bm; /* temporary bitmap */
  39.         nsfb_t *current; /* current main fb */
  40.         int width, height; /* target bitmap width height */
  41.         int cwidth, cheight;/* content width /height */
  42.         nsfb_bbox_t loc;
  43.  
  44.         struct redraw_context ctx = {
  45.                 .interactive = false,
  46.                 .background_images = true,
  47.                 .plot = &fb_plotters
  48.         };
  49.  
  50.  
  51.         nsfb_get_geometry(tbm, &width, &height, NULL);
  52.  
  53.         LOG(("width %d, height %d", width, height));
  54.  
  55.         /* Calculate size of buffer to render the content into */
  56.         /* We get the width from the content width, unless it exceeds 1024,
  57.          * in which case we use 1024. This means we never create excessively
  58.          * large render buffers for huge contents, which would eat memory and
  59.          * cripple performance. */
  60.         cwidth = min(content_get_width(content), 1024);
  61.         /* The height is set in proportion with the width, according to the
  62.          * aspect ratio of the required thumbnail. */
  63.         cheight = ((cwidth * height) + (width / 2)) / width;
  64.  
  65.         /* create temporary surface */
  66.         bm = nsfb_new(NSFB_SURFACE_RAM);
  67.         if (bm == NULL) {
  68.                 return false;
  69.         }
  70.  
  71.         nsfb_set_geometry(bm, cwidth, cheight, NSFB_FMT_XBGR8888);
  72.  
  73.         if (nsfb_init(bm) == -1) {
  74.                 nsfb_free(bm);
  75.                 return false;
  76.         }
  77.  
  78.         current = framebuffer_set_surface(bm);
  79.  
  80.         /* render the content into temporary surface */
  81.         thumbnail_redraw(content, cwidth, cheight, &ctx);
  82.  
  83.         framebuffer_set_surface(current);
  84.  
  85.         loc.x0 = 0;
  86.         loc.y0 = 0;
  87.         loc.x1 = width;
  88.         loc.y1 = height;
  89.  
  90.         nsfb_plot_copy(bm, NULL, tbm, &loc);
  91.  
  92.         nsfb_free(bm);
  93.  
  94.         /* register the thumbnail with the URL */
  95.         if (url != NULL)
  96.                 urldb_set_thumbnail(url, bitmap);
  97.  
  98.         return true;
  99. }
  100.