Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright 2008 Vincent Sanders <vince@simtec.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 <sys/types.h>
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include <limits.h>
  23.  
  24. #include "utils/log.h"
  25. #include "utils/utf8.h"
  26. #include "desktop/plotters.h"
  27.  
  28. #include "framebuffer/fb_gui.h"
  29. #include "framebuffer/fb_plotters.h"
  30. #include "framebuffer/fb_bitmap.h"
  31. #include "framebuffer/fb_font.h"
  32.  
  33. extern struct fb_info_s *fbinfo;
  34.  
  35.  
  36. static bool fb_1bpp_rectangle(int x0, int y0, int width, int height,
  37.                         int line_width, colour c, bool dotted, bool dashed)
  38. {
  39.         LOG(("%s(%d, %d, %d, %d, %d, 0x%lx, %d, %d)\n", __func__,
  40.              x0,y0,width,height,line_width,c,dotted,dashed));
  41.         return true;
  42. }
  43.  
  44. static bool fb_1bpp_line(int x0, int y0, int x1, int y1, int width,
  45.                         colour c, bool dotted, bool dashed)
  46. {
  47.         LOG(("%s(%d, %d, %d, %d, %d, 0x%lx, %d, %d)\n", __func__,
  48.              x0,y0,x1,y1,width,c,dotted,dashed));
  49.  
  50.         return true;
  51. }
  52.  
  53. static bool fb_1bpp_polygon(const int *p, unsigned int n, colour fill)
  54. {
  55.         LOG(("%s(%p, %d, 0x%lx)\n", __func__, p,n,fill));
  56.         return true;
  57. }
  58.  
  59.  
  60. static bool fb_1bpp_fill(int x0, int y0, int x1, int y1, colour c)
  61. {
  62.         int x;
  63.         int y;
  64.         int pent;
  65.  
  66.         LOG(("%s(%d, %d, %d, %d, 0x%lx)\n", __func__,
  67.              x0,y0,x1,y1,c));
  68.  
  69.         if (c != 0)
  70.                 pent = 0xff;
  71.         else
  72.                 pent = 0;
  73.  
  74.         fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1);
  75.      
  76.         x = x1 - x0;
  77.         for (y = y0; y < y1; y++) {
  78.                 memset(fb_plotters_get_xy_loc(x0, y, fbinfo), pent, x);
  79.         }
  80.         return true;
  81. }
  82.  
  83. static bool fb_1bpp_clg(colour c)
  84. {
  85.         LOG(("%s(%lx)\n", __func__, c));
  86.         fb_1bpp_fill(fb_plot_ctx.x0,
  87.                      fb_plot_ctx.y0,
  88.                      fb_plot_ctx.x1,
  89.                      fb_plot_ctx.y1,
  90.                      c);
  91.         return true;
  92. }
  93.  
  94.  
  95. static bool fb_1bpp_text(int x, int y, const struct css_style *style,
  96.                   const char *text, size_t length, colour bg, colour c)
  97. {
  98.         const struct fb_font_desc* fb_font = fb_get_font(style);
  99.         u8_t *video_char_start;
  100.         const u8_t *font_data;
  101.         int yloop;
  102.         unsigned char row;
  103.         int chr;
  104.  
  105.         LOG(("%s(%d, %d, %p, %.*s , %d, 0x%lx, 0x%lx)\n", __func__,
  106.              x,y,style,length,text,length,bg,c));
  107.  
  108.         for (chr=0; chr < length; chr++) {
  109.                 video_char_start = fb_plotters_get_xy_loc(x + (chr * (fb_font->width)), y, fbinfo);
  110.  
  111.                 /* move our font-data to the correct position */
  112.                 font_data = fb_font->data + (text[chr] * fb_font->height);
  113.  
  114.                 for (yloop = 0; yloop < fb_font->height; yloop++) {
  115.                         row = font_data[yloop];
  116.                         *video_char_start = row;
  117.                         video_char_start += fbinfo->line_len;
  118.                 }
  119.         }
  120.         return true;
  121.  
  122.  
  123.         /* copied from css/css.h - need to open the correct font here
  124.          * font properties *
  125.          css_font_family font_family;
  126.          struct {
  127.          css_font_size_type size;
  128.          union {
  129.          struct css_length length;
  130.          float absolute;
  131.          float percent;
  132.          } value;
  133.          } font_size;
  134.          css_font_style font_style;
  135.          css_font_variant font_variant;
  136.          css_font_weight font_weight;
  137.         */
  138.         return true;
  139. }
  140.  
  141. static bool fb_1bpp_disc(int x, int y, int radius, colour c, bool filled)
  142. {
  143.         LOG(("%s(%d, %d, %d, 0x%lx, %d)\n", __func__,
  144.              x, y, radius, c, filled));
  145.         return true;
  146. }
  147.  
  148. static bool fb_1bpp_arc(int x, int y, int radius, int angle1, int angle2,
  149.                         colour c)
  150. {
  151.         LOG(("x %d, y %d, radius %d, angle1 %d, angle2 %d, c 0x%lx",
  152.              x, y, radius, angle1, angle2, c));
  153.         return true;
  154. }
  155.  
  156. static inline colour ablend(colour pixel)
  157. {
  158.         return pixel;
  159. }
  160.  
  161.  
  162. static bool fb_1bpp_bitmap(int x, int y, int width, int height,
  163.                         struct bitmap *bitmap, colour bg,
  164.                         struct content *content)
  165. {
  166.         u8_t *video_char_start;
  167.         colour *pixel = (colour *)bitmap->pixdata;
  168.         colour abpixel; /* alphablended pixel */
  169.         int xloop,yloop;
  170.  
  171.         video_char_start = fb_plotters_get_xy_loc(x, y, fbinfo);
  172.  
  173.         for (yloop = 0; yloop < height; yloop++) {
  174.                 for (xloop = 0; xloop < width; xloop++) {
  175.                         abpixel = pixel[(yloop * bitmap->width) + xloop];
  176.                         if ((abpixel & 0xFF000000) != 0) {
  177.                                 if ((abpixel & 0xFF000000) != 0xFF)
  178.                                         abpixel = ablend(abpixel);
  179.                                 if (abpixel == 0)
  180.                                         video_char_start[xloop] |= (1 << (xloop % 8));
  181.                                 else
  182.                                         video_char_start[xloop] &= ~(1 << (xloop % 8));
  183.  
  184.                         }
  185.                 }
  186.                 video_char_start += fbinfo->line_len;
  187.         }
  188.  
  189.         return true;
  190. }
  191.  
  192. static bool fb_1bpp_bitmap_tile(int x, int y, int width, int height,
  193.                         struct bitmap *bitmap, colour bg,
  194.                         bool repeat_x, bool repeat_y,
  195.                              struct content *content)
  196. {
  197.         unsigned long xf,yf,wf,hf;
  198.  
  199.         if (!(repeat_x || repeat_y)) {
  200.                 /* Not repeating at all, so just pass it on */
  201.                 return fb_1bpp_bitmap(x,y,width,height,bitmap,bg,content);
  202.         }
  203.  
  204.         for (xf = 0; xf < width; xf += bitmap->width) {
  205.                 for(yf = 0;yf < height; yf += bitmap->height) {
  206.                         if(width > xf+bitmap->width)
  207.                         {
  208.                                 wf = width-(xf+bitmap->width);
  209.                         }
  210.                         else
  211.                         {
  212.                                 wf=bitmap->width;
  213.                         }
  214.  
  215.                         if(height > yf+bitmap->height)
  216.                         {
  217.                                 hf = height-(yf+bitmap->height);
  218.                         }
  219.                         else
  220.                         {
  221.                                 hf=bitmap->height;
  222.                         }
  223.  
  224.                         fb_1bpp_bitmap(x+xf, y+yf, wf, hf, bitmap, bg, content);
  225.  
  226.                 }
  227.         }
  228.  
  229.         return true;
  230. }
  231.  
  232. static bool fb_1bpp_flush(void)
  233. {
  234.         LOG(("%s()\n", __func__));
  235.         return true;
  236. }
  237.  
  238. static bool fb_1bpp_path(const float *p, unsigned int n, colour fill, float width,
  239.                         colour c, const float transform[6])
  240. {
  241.         LOG(("%s(%f, %d, 0x%lx, %f, 0x%lx, %f)\n", __func__,
  242.              *p, n, fill, width, c, *transform));
  243.         return true;
  244. }
  245.  
  246. const struct plotter_table framebuffer_1bpp_plot = {
  247.         .clg = fb_1bpp_clg,
  248.         .rectangle = fb_1bpp_rectangle,
  249.         .line = fb_1bpp_line,
  250.         .polygon = fb_1bpp_polygon,
  251.         .fill = fb_1bpp_fill,
  252.         .clip = fb_clip,
  253.         .text = fb_1bpp_text,
  254.         .disc = fb_1bpp_disc,
  255.         .arc = fb_1bpp_arc,
  256.         .bitmap = fb_1bpp_bitmap,
  257.         .bitmap_tile = fb_1bpp_bitmap_tile,
  258.         .flush = fb_1bpp_flush,
  259.         .path = fb_1bpp_path
  260. };
  261.  
  262. /*
  263.  * Local Variables:
  264.  * c-basic-offset:8
  265.  * End:
  266.  */
  267.