From c85268379ba1d4fc3a69c6ce8b28c69314ebd435 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 26 Feb 2009 21:37:22 +0000 Subject: try and improve plotter perfomance futher svn path=/trunk/netsurf/; revision=6644 --- framebuffer/fb_16bpp_plotters.c | 54 ++++++++++++++++++----------------------- framebuffer/fb_32bpp_plotters.c | 14 ++++------- framebuffer/fb_plotters.c | 17 ------------- framebuffer/fb_plotters.h | 19 ++++++++++++++- 4 files changed, 46 insertions(+), 58 deletions(-) diff --git a/framebuffer/fb_16bpp_plotters.c b/framebuffer/fb_16bpp_plotters.c index 2fa98ce7d..e74f309b4 100644 --- a/framebuffer/fb_16bpp_plotters.c +++ b/framebuffer/fb_16bpp_plotters.c @@ -45,6 +45,12 @@ static inline colour fb_16bpp_to_colour(uint16_t pixel) ((pixel & 0xF800) >> 8); } +/* convert a colour value to a 16bpp pixel value ready for screen output */ +static inline uint16_t fb_colour_to_pixel(colour c) +{ + return ((c & 0xF8) << 8) | ((c & 0xFC00 ) >> 5) | ((c & 0xF80000) >> 19); +} + #define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0)) static bool fb_16bpp_line(int x0, int y0, int x1, int y1, int width, @@ -66,9 +72,7 @@ static bool fb_16bpp_line(int x0, int y0, int x1, int y1, int width, if (y0 < fb_plot_ctx.y0) return true; - ent = ((c & 0xF8) << 8) | - ((c & 0xFC00 ) >> 5) | - ((c & 0xF80000) >> 19); + ent = fb_colour_to_pixel(c); if (y0 == y1) { /* horizontal line special cased */ @@ -162,25 +166,25 @@ static bool fb_16bpp_polygon(const int *p, unsigned int n, colour fill) static bool fb_16bpp_fill(int x0, int y0, int x1, int y1, colour c) { int w; - int y; + uint16_t *pvid; uint16_t ent; - uint16_t *pvideo; + uint32_t llen; + uint32_t width; + uint32_t height; if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1)) return true; /* fill lies outside current clipping region */ - ent = ((c & 0xF8) << 8) | - ((c & 0xFC00 ) >> 5) | - ((c & 0xF80000) >> 19); + ent = fb_colour_to_pixel(c); + width = x1 - x0; + height = y1 - y0; + llen = (framebuffer->linelen >> 1) - width; - pvideo = fb_16bpp_get_xy_loc(x0, y0); + pvid = fb_16bpp_get_xy_loc(x0, y0); - for (y = y0; y < y1; y++) { - w = x1 - x0; - while (w-- > 0) { - *(pvideo + w) = ent; - } - pvideo += (framebuffer->linelen >> 1); + while (height-- > 0) { + for (w = width; w > 0; w--) *pvid++ = ent; + pvid += llen; } return true; @@ -252,10 +256,7 @@ fb_16bpp_draw_ft_bitmap(FT_Bitmap *bp, int x, int y, colour c) fb_16bpp_to_colour(*(pvideo + xloop))); } - *(pvideo + xloop) = - ((abpixel & 0xF8) << 8) | - ((abpixel & 0xFC00 ) >> 5) | - ((abpixel & 0xF80000) >> 19); + *(pvideo + xloop) = fb_colour_to_pixel(abpixel); } } @@ -351,14 +352,9 @@ static bool fb_16bpp_text(int x, int y, const struct css_style *style, xoff = x0 - x; yoff = y0 - y; - fgcol = ((c & 0xF8) << 8) | - ((c & 0xFC00 ) >> 5) | - ((c & 0xF80000) >> 19); - - bgcol = ((bg & 0xF8) << 8) | - ((bg & 0xFC00 ) >> 5) | - ((bg & 0xF80000) >> 19); + fgcol = fb_colour_to_pixel(c); + bgcol = fb_colour_to_pixel(bg); /*LOG(("x %d, y %d, style %p, txt %.*s , len %d, bg 0x%lx, fg 0x%lx", x,y,style,length,text,length,bg,c));*/ @@ -463,11 +459,7 @@ static bool fb_16bpp_bitmap(int x, int y, int width, int height, fb_16bpp_to_colour(*(pvideo + xloop))); } - *(pvideo + xloop) = - ((abpixel & 0xF8) << 8) | - ((abpixel & 0xFC00 ) >> 5) | - ((abpixel & 0xF80000) >> 19); - + *(pvideo + xloop) = fb_colour_to_pixel(abpixel); } } pvideo += (framebuffer->linelen >> 1); diff --git a/framebuffer/fb_32bpp_plotters.c b/framebuffer/fb_32bpp_plotters.c index f8284c5f8..45af64626 100644 --- a/framebuffer/fb_32bpp_plotters.c +++ b/framebuffer/fb_32bpp_plotters.c @@ -174,7 +174,6 @@ static bool fb_32bpp_polygon(const int *p, unsigned int n, colour fill) static bool fb_32bpp_fill(int x0, int y0, int x1, int y1, colour c) { int w; - uint32_t *pvid_line; uint32_t *pvid; uint32_t ent; uint32_t llen; @@ -185,18 +184,15 @@ static bool fb_32bpp_fill(int x0, int y0, int x1, int y1, colour c) return true; /* fill lies outside current clipping region */ ent = fb_colour_to_pixel(c); - llen = (framebuffer->linelen >> 2); width = x1 - x0; height = y1 - y0; + llen = (framebuffer->linelen >> 2) - width; - pvid_line = fb_32bpp_get_xy_loc(x0, y0); + pvid = fb_32bpp_get_xy_loc(x0, y0); - while (height > 0) { - height--; - pvid = pvid_line; - pvid_line += llen; - w = width; - while (w-- > 0) *pvid++ = ent; + while (height-- > 0) { + for (w = width; w > 0; w--) *pvid++ = ent; + pvid += llen; } return true; diff --git a/framebuffer/fb_plotters.c b/framebuffer/fb_plotters.c index c99c63c2c..773cc640a 100644 --- a/framebuffer/fb_plotters.c +++ b/framebuffer/fb_plotters.c @@ -210,23 +210,6 @@ bool fb_clip(int x0, int y0, int x1, int y1) return true; } -colour fb_plotters_ablend(colour pixel, colour scrpixel) -{ - int opacity = (pixel >> 24) & 0xFF; - int r,g,b; - - r = (((pixel & 0xFF) * opacity) >> 8) + - (((scrpixel & 0xFF) * (0xFF - opacity)) >> 8); - - g = ((((pixel & 0xFF00) >> 8) * opacity) >> 8) + - ((((scrpixel & 0xFF00) >> 8) * (0xFF - opacity)) >> 8); - - b = ((((pixel & 0xFF0000) >> 16) * opacity) >> 8) + - ((((scrpixel & 0xFF0000) >> 16) * (0xFF - opacity)) >> 8); - - return r | (g << 8) | (b << 16); -} - typedef bool (linefn_t)(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed); typedef struct dcPt_s { diff --git a/framebuffer/fb_plotters.h b/framebuffer/fb_plotters.h index c06ad2961..33a929b5c 100644 --- a/framebuffer/fb_plotters.h +++ b/framebuffer/fb_plotters.h @@ -47,7 +47,24 @@ bool fb_plotters_bitmap_tile(int x, int y, colour bg, struct content *content)); -colour fb_plotters_ablend(colour pixel, colour scrpixel); +/* alpha blend two pixels together */ +static inline colour fb_plotters_ablend(colour pixel, colour scrpixel) +{ + int opacity = (pixel >> 24) & 0xFF; + int r,g,b; + + r = (((pixel & 0xFF) * opacity) >> 8) + + (((scrpixel & 0xFF) * (0xFF - opacity)) >> 8); + + g = ((((pixel & 0xFF00) >> 8) * opacity) >> 8) + + ((((scrpixel & 0xFF00) >> 8) * (0xFF - opacity)) >> 8); + + b = ((((pixel & 0xFF0000) >> 16) * opacity) >> 8) + + ((((scrpixel & 0xFF0000) >> 16) * (0xFF - opacity)) >> 8); + + return r | (g << 8) | (b << 16); +} + bool fb_plotters_move_block(int srcx, int srcy, int width, int height, int dstx, int dsty); -- cgit v1.2.3