From b8e5897b4edb640012f43dc87b7c84194163a153 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 1 Feb 2019 23:01:03 +0100 Subject: use pixman for image blit+blend --- fb-gui.c | 62 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'fb-gui.c') diff --git a/fb-gui.c b/fb-gui.c index f8447b7..a55026f 100644 --- a/fb-gui.c +++ b/fb-gui.c @@ -8,8 +8,11 @@ #include #include +#include + #include "vt.h" #include "fbtools.h" +#include "readers.h" #include "fb-gui.h" static int ys = 3; @@ -25,6 +28,7 @@ static unsigned int *sdirty,swidth,sheight; static cairo_t *context; static cairo_surface_t *surface; +static pixman_image_t *pixman; static unsigned char *framebuffer; static cairo_font_extents_t extents; @@ -106,12 +110,19 @@ void shadow_render(gfxstate *gfx) void shadow_clear_lines(int first, int last) { +#if 0 + /* FIXME: segfaults */ + cairo_rectangle(context, 0, first, swidth, last - first + 1); + cairo_set_source_rgb(context, 0, 0, 0); + cairo_fill(context); +#else int i; for (i = first; i <= last; i++) { memset(shadow[i],0,4*swidth); sdirty[i]++; } +#endif } void shadow_clear(void) @@ -153,6 +164,9 @@ void shadow_init(gfxstate *gfx) swidth, sheight, swidth * 4); context = cairo_create(surface); + pixman = pixman_image_create_bits(PIXMAN_x8r8g8b8, swidth, sheight, + (void*)framebuffer, swidth * 4); + /* init rendering */ switch (gfx->bits_per_pixel) { @@ -208,40 +222,28 @@ void shadow_draw_rect(int x1, int x2, int y1, int y2) shadow_set_dirty_range(y1, (y2 - y1) + 1); } -void shadow_draw_rgbdata(int x, int y, int pixels, unsigned char *rgb) +void shadow_composite_image(struct ida_image *img, + int xoff, int yoff, int weight) { - unsigned char *dest = shadow[y] + 4*x; - int i; - - for (i = 0; i < pixels; i++) { - dest[0] = rgb[2]; - dest[1] = rgb[1]; - dest[2] = rgb[0]; - dest += 4; - rgb += 3; + if (weight == 100) { + pixman_image_composite(PIXMAN_OP_SRC, img->p, NULL, pixman, + 0, 0, 0, 0, + xoff, yoff, + img->i.width, img->i.height); + } else { + pixman_color_t color = { + .alpha = weight * 0xffff / 100, + }; + pixman_image_t *mask = pixman_image_create_solid_fill(&color); + + pixman_image_composite(PIXMAN_OP_OVER, img->p, mask, pixman, + 0, 0, 0, 0, + xoff, yoff, + img->i.width, img->i.height); + pixman_image_unref(mask); } - sdirty[y]++; } -void shadow_merge_rgbdata(int x, int y, int pixels, int weight, - unsigned char *rgb) -{ - unsigned char *dest = shadow[y] + 4*x; - int i; - - weight = weight * 256 / 100; - - for (i = 0; i < pixels; i++) { - dest[0] += rgb[2] * weight >> 8; - dest[1] += rgb[1] * weight >> 8; - dest[2] += rgb[0] * weight >> 8; - dest += 4; - rgb += 3; - } - sdirty[y]++; -} - - void shadow_darkify(int x1, int x2, int y1,int y2, int percent) { cairo_rectangle(context, x1, y1, -- cgit