From c11fee4ce3028689109579916aa26f985ecda281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 22 Sep 2019 01:56:58 +0200 Subject: [PATCH] cairo: replace cairo with pixman in decos, particles and modules All decoration, particle and module interfaces now takes a pixman_image_t parameter, and all drawing is done using pixman APIs. The wayland/xcb backends implement a new interface functions, get_pixman_image(), that should return a pixman image instance that is suitable for rendering. In the wayland backend, the image uses the same backing data as the cairo surface. In the XCB backend, we create a new image each time, and then blit it to the cairo surface at commit time. --- bar/backend.h | 3 ++- bar/bar.c | 45 +++++++++++++---------------------- bar/bar.h | 4 ++-- bar/private.h | 4 ++-- bar/wayland.c | 24 +++++++++++++++++-- bar/xcb.c | 51 ++++++++++++++++++++++++++++++++++++++-- config.c | 40 +++++++++++++++---------------- config.h | 4 ++-- decoration.h | 4 ++-- decorations/background.c | 14 +++++------ decorations/meson.build | 2 +- decorations/stack.c | 4 ++-- decorations/underline.c | 13 +++++----- modules/meson.build | 2 +- particle.c | 6 ++--- particle.h | 10 ++++---- particles/dynlist.c | 4 ++-- particles/empty.c | 4 ++-- particles/list.c | 6 ++--- particles/map.c | 6 ++--- particles/meson.build | 2 +- particles/progress-bar.c | 6 ++--- particles/ramp.c | 6 ++--- particles/string.c | 39 +++--------------------------- 24 files changed, 162 insertions(+), 141 deletions(-) diff --git a/bar/backend.h b/bar/backend.h index c07e069..782bb98 100644 --- a/bar/backend.h +++ b/bar/backend.h @@ -11,7 +11,8 @@ struct backend { void (*expose)(const struct bar *bar), void (*on_mouse)(struct bar *bar, enum mouse_event event, int x, int y)); - void (*commit_surface)(const struct bar *bar); + pixman_image_t *(*get_pixman_image)(const struct bar *bar); + void (*commit_pixman)(const struct bar *bar, pixman_image_t *pix); void (*refresh)(const struct bar *bar); void (*set_cursor)(struct bar *bar, const char *cursor); }; diff --git a/bar/bar.c b/bar/bar.c index df74d7d..be048a3 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -61,33 +61,21 @@ static void expose(const struct bar *_bar) { const struct private *bar = _bar->private; + pixman_image_t *pix = bar->backend.iface->get_pixman_image(_bar); - double r, g, b, a; - r = bar->background.red; - g = bar->background.green; - b = bar->background.blue; - a = bar->background.alpha; - - cairo_set_source_rgba(bar->cairo, r, g, b, a); - cairo_set_operator(bar->cairo, CAIRO_OPERATOR_SOURCE); - cairo_paint(bar->cairo); + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, pix, &bar->background, 1, + &(pixman_rectangle16_t){0, 0, bar->width, bar->height_with_border}); if (bar->border.width > 0) { - r = bar->border.color.red; - g = bar->border.color.green; - b = bar->border.color.blue; - a = bar->border.color.alpha; - - cairo_set_line_width(bar->cairo, bar->border.width); - cairo_set_source_rgba(bar->cairo, r, g, b, a); - cairo_set_operator(bar->cairo, CAIRO_OPERATOR_OVER); - cairo_rectangle( - bar->cairo, - bar->border.width / 2.0, - bar->border.width / 2.0, - bar->width - bar->border.width, - bar->height_with_border - bar->border.width); - cairo_stroke(bar->cairo); + pixman_image_fill_rectangles( + PIXMAN_OP_OVER, pix, &bar->border.color, 4, + (pixman_rectangle16_t[]){ + {0, 0, bar->width, bar->border.width}, + {0, 0, bar->border.width, bar->height}, + {bar->width - bar->border.width, 0, bar->border.width, bar->height}, + {0, bar->height - bar->border.width, bar->width, bar->border.width}, + }); } for (size_t i = 0; i < bar->left.count; i++) { @@ -127,14 +115,14 @@ expose(const struct bar *_bar) int x = bar->border.width + bar->left_margin - bar->left_spacing; for (size_t i = 0; i < bar->left.count; i++) { const struct exposable *e = bar->left.exps[i]; - e->expose(e, bar->cairo, x + bar->left_spacing, y, bar->height); + e->expose(e, pix, x + bar->left_spacing, y, bar->height); x += bar->left_spacing + e->width + bar->right_spacing; } x = bar->width / 2 - center_width / 2 - bar->left_spacing; for (size_t i = 0; i < bar->center.count; i++) { const struct exposable *e = bar->center.exps[i]; - e->expose(e, bar->cairo, x + bar->left_spacing, y, bar->height); + e->expose(e, pix, x + bar->left_spacing, y, bar->height); x += bar->left_spacing + e->width + bar->right_spacing; } @@ -146,12 +134,11 @@ expose(const struct bar *_bar) for (size_t i = 0; i < bar->right.count; i++) { const struct exposable *e = bar->right.exps[i]; - e->expose(e, bar->cairo, x + bar->left_spacing, y, bar->height); + e->expose(e, pix, x + bar->left_spacing, y, bar->height); x += bar->left_spacing + e->width + bar->right_spacing; } - cairo_surface_flush(bar->cairo_surface); - bar->backend.iface->commit_surface(_bar); + bar->backend.iface->commit_pixman(_bar, pix); } diff --git a/bar/bar.h b/bar/bar.h index 108a972..78e2414 100644 --- a/bar/bar.h +++ b/bar/bar.h @@ -26,11 +26,11 @@ struct bar_config { int left_spacing, right_spacing; int left_margin, right_margin; - struct rgba background; + pixman_color_t background; struct { int width; - struct rgba color; + pixman_color_t color; int left_margin, right_margin; int top_margin, bottom_margin; } border; diff --git a/bar/private.h b/bar/private.h index 0f86e86..c41d4a7 100644 --- a/bar/private.h +++ b/bar/private.h @@ -14,11 +14,11 @@ struct private { int left_spacing, right_spacing; int left_margin, right_margin; - struct rgba background; + pixman_color_t background; struct { int width; - struct rgba color; + pixman_color_t color; int left_margin, right_margin; int top_margin, bottom_margin; } border; diff --git a/bar/wayland.c b/bar/wayland.c index f53bce4..4e65bf2 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -901,12 +901,31 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da ;//printf("nothing more to do\n"); } +static pixman_image_t * +get_pixman_image(const struct bar *_bar) +{ + struct private *bar = _bar->private; + + cairo_surface_t *surf = cairo_get_target(bar->cairo); + cairo_surface_flush(surf); + + return pixman_image_create_bits_no_clear( + PIXMAN_a8r8g8b8, + cairo_image_surface_get_width(surf), + cairo_image_surface_get_height(surf), + (uint32_t *)cairo_image_surface_get_data(surf), + cairo_image_surface_get_stride(surf)); +} + static void -commit_surface(const struct bar *_bar) +commit_pixman(const struct bar *_bar, pixman_image_t *pix) { struct private *bar = _bar->private; struct wayland_backend *backend = bar->backend.data; + pixman_image_unref(pix); + cairo_surface_mark_dirty(cairo_get_target(bar->cairo)); + //printf("commit: %dxl%d\n", backend->width, backend->height); assert(backend->next_buffer != NULL); @@ -973,7 +992,8 @@ const struct backend wayland_backend_iface = { .setup = &setup, .cleanup = &cleanup, .loop = &loop, - .commit_surface = &commit_surface, + .get_pixman_image = &get_pixman_image, + .commit_pixman = &commit_pixman, .refresh = &refresh, .set_cursor = &set_cursor, }; diff --git a/bar/xcb.c b/bar/xcb.c index f2dcd3c..3b71d27 100644 --- a/bar/xcb.c +++ b/bar/xcb.c @@ -370,10 +370,56 @@ loop(struct bar *_bar, } static void -commit_surface(const struct bar *_bar) +free_pixman_bits(pixman_image_t *pix, void *data) +{ + free(data); +} + +static pixman_image_t * +get_pixman_image(const struct bar *_bar) +{ + const struct private *bar = _bar->private; + uint32_t *bits = malloc( + bar->width * bar->height_with_border * sizeof(uint32_t)); + + pixman_image_t *ret = pixman_image_create_bits_no_clear( + PIXMAN_a8r8g8b8, + bar->width, + bar->height_with_border, + bits, + bar->width * sizeof(uint32_t)); + + if (ret == NULL) { + free(bits); + return NULL; + } + + pixman_image_set_destroy_function(ret, &free_pixman_bits, bits); + return ret; +} + +static void +commit_pixman(const struct bar *_bar, pixman_image_t *pix) { const struct private *bar = _bar->private; const struct xcb_backend *backend = bar->backend.data; + + /* Blit pixman image to our XCB surface */ + cairo_surface_t *surf = cairo_image_surface_create_for_data( + (unsigned char *)pixman_image_get_data(pix), + CAIRO_FORMAT_ARGB32, + bar->width, + bar->height_with_border, + cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bar->width)); + + cairo_set_source_surface(bar->cairo, surf, 0, 0); + cairo_set_operator(bar->cairo, CAIRO_OPERATOR_SOURCE); + cairo_paint(bar->cairo); + + cairo_surface_flush(bar->cairo_surface); + cairo_surface_destroy(surf); + pixman_image_unref(pix); + xcb_copy_area(backend->conn, backend->pixmap, backend->win, backend->gc, 0, 0, 0, 0, bar->width, bar->height_with_border); xcb_flush(backend->conn); @@ -430,7 +476,8 @@ const struct backend xcb_backend_iface = { .setup = &setup, .cleanup = &cleanup, .loop = &loop, - .commit_surface = &commit_surface, + .get_pixman_image = &get_pixman_image, + .commit_pixman = &commit_pixman, .refresh = &refresh, .set_cursor = &set_cursor, }; diff --git a/config.c b/config.c index 01a985d..7a885dc 100644 --- a/config.c +++ b/config.c @@ -13,6 +13,10 @@ #include "module.h" #include "plugin.h" +#define LOG_MODULE "config" +#define LOG_ENABLE_DBG 0 +#include "log.h" + static uint8_t hex_nibble(char hex) { @@ -36,7 +40,7 @@ hex_byte(const char hex[2]) return upper << 4 | lower; } -struct rgba +pixman_color_t conf_to_color(const struct yml_node *node) { const char *hex = yml_value_as_string(node); @@ -44,30 +48,26 @@ conf_to_color(const struct yml_node *node) assert(hex != NULL); assert(strlen(hex) == 8); - uint8_t red = hex_byte(&hex[0]); - uint8_t green = hex_byte(&hex[2]); - uint8_t blue = hex_byte(&hex[4]); - uint8_t alpha = hex_byte(&hex[6]); + uint16_t red = hex_byte(&hex[0]); + uint16_t green = hex_byte(&hex[2]); + uint16_t blue = hex_byte(&hex[4]); + uint16_t alpha = hex_byte(&hex[6]); - struct rgba rgba = { - (double)red / 255.0, - (double)green / 255.0, - (double)blue / 255.0, - (double)alpha / 255.0 + alpha |= alpha << 8; + int alpha_div = 0xffff / alpha; + + return (pixman_color_t){ + .red = (red << 8 | red) / alpha_div, + .green = (green << 8 | green) / alpha_div, + .blue = (blue << 8 | blue) / alpha_div, + .alpha = alpha, }; - - assert(rgba.red >= 0.0 && rgba.red <= 1.0); - assert(rgba.green >= 0.0 && rgba.green <= 1.0); - assert(rgba.blue >= 0.0 && rgba.blue <= 1.0); - assert(rgba.alpha >= 0.0 && rgba.alpha <= 1.0); - - return rgba; } struct font * conf_to_font(const struct yml_node *node) { - return font_from_name(yml_value_as_string(node));; + return font_from_name(yml_value_as_string(node)); } struct deco * @@ -155,7 +155,7 @@ conf_to_particle(const struct yml_node *node, struct conf_inherit inherited) */ struct font *font = font_node != NULL ? conf_to_font(font_node) : font_clone(inherited.font); - struct rgba foreground = foreground_node != NULL + pixman_color_t foreground = foreground_node != NULL ? conf_to_color(foreground_node) : inherited.foreground; /* Instantiate base/common particle */ @@ -264,7 +264,7 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend) * foreground color at top-level. */ struct font *font = font_from_name("sans"); - struct rgba foreground = (struct rgba){1.0, 1.0, 1.0, 1.0}; /* White */ + pixman_color_t foreground = {0xffff, 0xffff, 0xffff, 0xffff}; /* White */ const struct yml_node *font_node = yml_get_value(bar, "font"); if (font_node != NULL) { diff --git a/config.h b/config.h index a909c60..28e3f5a 100644 --- a/config.h +++ b/config.h @@ -14,12 +14,12 @@ struct bar *conf_to_bar(const struct yml_node *bar, enum bar_backend backend); * Utility functions, for e.g. modules */ -struct rgba conf_to_color(const struct yml_node *node); +pixman_color_t conf_to_color(const struct yml_node *node); struct font *conf_to_font(const struct yml_node *node); struct conf_inherit { const struct font *font; - struct rgba foreground; + pixman_color_t foreground; }; struct particle *conf_to_particle( diff --git a/decoration.h b/decoration.h index 78f2f05..efb79e2 100644 --- a/decoration.h +++ b/decoration.h @@ -1,10 +1,10 @@ #pragma once -#include +#include struct deco { void *private; - void (*expose)(const struct deco *deco, cairo_t *cr, + void (*expose)(const struct deco *deco, pixman_image_t *pix, int x, int y, int width, int height); void (*destroy)(struct deco *deco); }; diff --git a/decorations/background.c b/decorations/background.c index ef7b12b..b3b9ed2 100644 --- a/decorations/background.c +++ b/decorations/background.c @@ -6,7 +6,8 @@ #include "../plugin.h" struct private { - struct rgba color; + //struct rgba color; + pixman_color_t color; }; static void @@ -18,17 +19,16 @@ destroy(struct deco *deco) } static void -expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height) +expose(const struct deco *deco, pixman_image_t *pix, int x, int y, int width, int height) { const struct private *d = deco->private; - cairo_set_source_rgba( - cr, d->color.red, d->color.green, d->color.blue, d->color.alpha); - cairo_rectangle(cr, x, y, width, height); - cairo_fill(cr); + pixman_image_fill_rectangles( + PIXMAN_OP_OVER, pix, &d->color, 1, + &(pixman_rectangle16_t){x, y, width, height}); } static struct deco * -background_new(struct rgba color) +background_new(pixman_color_t color) { struct private *priv = calloc(1, sizeof(*priv)); priv->color = color; diff --git a/decorations/meson.build b/decorations/meson.build index 1b6daee..f96c80b 100644 --- a/decorations/meson.build +++ b/decorations/meson.build @@ -1,4 +1,4 @@ -deco_sdk = declare_dependency(dependencies: [cairo, cairo_ft]) +deco_sdk = declare_dependency(dependencies: [pixman]) decorations = [] foreach deco : ['background', 'stack', 'underline'] diff --git a/decorations/stack.c b/decorations/stack.c index 3ffaab5..16c58ee 100644 --- a/decorations/stack.c +++ b/decorations/stack.c @@ -24,11 +24,11 @@ destroy(struct deco *deco) } static void -expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height) +expose(const struct deco *deco, pixman_image_t *pix, int x, int y, int width, int height) { const struct private *d = deco->private; for (size_t i = 0; i < d->count; i++) - d->decos[i]->expose(d->decos[i], cr, x, y, width, height); + d->decos[i]->expose(d->decos[i], pix, x, y, width, height); } static struct deco * diff --git a/decorations/underline.c b/decorations/underline.c index 996d54a..a700bec 100644 --- a/decorations/underline.c +++ b/decorations/underline.c @@ -7,7 +7,7 @@ struct private { int size; - struct rgba color; + pixman_color_t color; }; static void @@ -19,17 +19,16 @@ destroy(struct deco *deco) } static void -expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height) +expose(const struct deco *deco, pixman_image_t *pix, int x, int y, int width, int height) { const struct private *d = deco->private; - cairo_set_source_rgba( - cr, d->color.red, d->color.green, d->color.blue, d->color.alpha); - cairo_rectangle(cr, x, y + height - d->size, width, d->size); - cairo_fill(cr); + pixman_image_fill_rectangles( + PIXMAN_OP_OVER, pix, &d->color, 1, + &(pixman_rectangle16_t){x, y + height - d->size, width, d->size}); } static struct deco * -underline_new(int size, struct rgba color) +underline_new(int size, pixman_color_t color) { struct private *priv = calloc(1, sizeof(*priv)); priv->size = size; diff --git a/modules/meson.build b/modules/meson.build index b156e18..5986c51 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -1,4 +1,4 @@ -module_sdk = declare_dependency(dependencies: [cairo, cairo_ft, threads]) +module_sdk = declare_dependency(dependencies: [pixman, threads]) modules = [] diff --git a/particle.c b/particle.c index c6e69ad..5c116bb 100644 --- a/particle.c +++ b/particle.c @@ -29,7 +29,7 @@ particle_default_destroy(struct particle *particle) struct particle * particle_common_new(int left_margin, int right_margin, const char *on_click_template, - struct font *font, struct rgba foreground, + struct font *font, pixman_color_t foreground, struct deco *deco) { struct particle *p = calloc(1, sizeof(*p)); @@ -52,11 +52,11 @@ exposable_default_destroy(struct exposable *exposable) void exposable_render_deco(const struct exposable *exposable, - cairo_t *cr, int x, int y, int height) + pixman_image_t *pix, int x, int y, int height) { const struct deco *deco = exposable->particle->deco; if (deco != NULL) - deco->expose(deco, cr, x, y, exposable->width, height); + deco->expose(deco, pix, x, y, exposable->width, height); } diff --git a/particle.h b/particle.h index 210530f..789fd87 100644 --- a/particle.h +++ b/particle.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include "color.h" #include "decoration.h" @@ -14,7 +14,7 @@ struct particle { int left_margin, right_margin; char *on_click_template; - struct rgba foreground; + pixman_color_t foreground; struct font *font; struct deco *deco; @@ -37,7 +37,7 @@ struct exposable { void (*destroy)(struct exposable *exposable); int (*begin_expose)(struct exposable *exposable); - void (*expose)(const struct exposable *exposable, cairo_t *cr, + void (*expose)(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height); void (*on_mouse)(struct exposable *exposable, struct bar *bar, @@ -46,7 +46,7 @@ struct exposable { struct particle *particle_common_new( int left_margin, int right_margin, const char *on_click_template, - struct font *font, struct rgba foreground, struct deco *deco); + struct font *font, pixman_color_t foreground, struct deco *deco); void particle_default_destroy(struct particle *particle); @@ -54,7 +54,7 @@ struct exposable *exposable_common_new( const struct particle *particle, const char *on_click); void exposable_default_destroy(struct exposable *exposable); void exposable_render_deco( - const struct exposable *exposable, cairo_t *cr, int x, int y, int height); + const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height); void exposable_default_on_mouse( struct exposable *exposable, struct bar *bar, diff --git a/particles/dynlist.c b/particles/dynlist.c index e6a3636..c04d610 100644 --- a/particles/dynlist.c +++ b/particles/dynlist.c @@ -49,7 +49,7 @@ dynlist_begin_expose(struct exposable *exposable) } static void -dynlist_expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +dynlist_expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { const struct private *e = exposable->private; @@ -60,7 +60,7 @@ dynlist_expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int for (size_t i = 0; i < e->count; i++) { const struct exposable *ee = e->exposables[i]; - ee->expose(ee, cr, x + left_spacing, y, height); + ee->expose(ee, pix, x + left_spacing, y, height); x += left_spacing + e->widths[i] + right_spacing; } } diff --git a/particles/empty.c b/particles/empty.c index 8b0cb39..e97f929 100644 --- a/particles/empty.c +++ b/particles/empty.c @@ -14,9 +14,9 @@ begin_expose(struct exposable *exposable) } static void -expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { - exposable_render_deco(exposable, cr, x, y, height); + exposable_render_deco(exposable, pix, x, y, height); } static struct exposable * diff --git a/particles/list.c b/particles/list.c index a47c468..720e8a5 100644 --- a/particles/list.c +++ b/particles/list.c @@ -55,11 +55,11 @@ begin_expose(struct exposable *exposable) } static void -expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { const struct eprivate *e = exposable->private; - exposable_render_deco(exposable, cr, x, y, height); + exposable_render_deco(exposable, pix, x, y, height); int left_margin = exposable->particle->left_margin; int left_spacing = e->left_spacing; @@ -68,7 +68,7 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) x += left_margin - left_spacing; for (size_t i = 0; i < e->count; i++) { const struct exposable *ee = e->exposables[i]; - ee->expose(ee, cr, x + left_spacing, y, height); + ee->expose(ee, pix, x + left_spacing, y, height); x += left_spacing + e->widths[i] + right_spacing; } } diff --git a/particles/map.c b/particles/map.c index a8895cb..2f5c460 100644 --- a/particles/map.c +++ b/particles/map.c @@ -49,13 +49,13 @@ begin_expose(struct exposable *exposable) } static void -expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { struct eprivate *e = exposable->private; - exposable_render_deco(exposable, cr, x, y, height); + exposable_render_deco(exposable, pix, x, y, height); e->exposable->expose( - e->exposable, cr, x + exposable->particle->left_margin, y, height); + e->exposable, pix, x + exposable->particle->left_margin, y, height); } static void diff --git a/particles/meson.build b/particles/meson.build index 2b867c8..837e418 100644 --- a/particles/meson.build +++ b/particles/meson.build @@ -1,4 +1,4 @@ -particle_sdk = declare_dependency(dependencies: [cairo, cairo_ft]) +particle_sdk = declare_dependency(dependencies: [freetype, fontconfig, pixman]) particles = [] foreach particle : ['empty', 'list', 'map', 'progress-bar', 'ramp', 'string'] diff --git a/particles/progress-bar.c b/particles/progress-bar.c index 762178e..e4e1715 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -70,15 +70,15 @@ begin_expose(struct exposable *exposable) } static void -expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { const struct eprivate *e = exposable->private; - exposable_render_deco(exposable, cr, x, y, height); + exposable_render_deco(exposable, pix, x, y, height); x += exposable->particle->left_margin; for (size_t i = 0; i < e->count; i++) { - e->exposables[i]->expose(e->exposables[i], cr, x, y, height); + e->exposables[i]->expose(e->exposables[i], pix, x, y, height); x += e->exposables[i]->width; } } diff --git a/particles/ramp.c b/particles/ramp.c index 1f8ef11..b513681 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -43,13 +43,13 @@ begin_expose(struct exposable *exposable) } static void -expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { struct eprivate *e = exposable->private; - exposable_render_deco(exposable, cr, x, y, height); + exposable_render_deco(exposable, pix, x, y, height); e->exposable->expose( - e->exposable, cr, x + exposable->particle->left_margin, y, height); + e->exposable, pix, x + exposable->particle->left_margin, y, height); } static void diff --git a/particles/string.c b/particles/string.c index 3ff0aa7..ec1fcdd 100644 --- a/particles/string.c +++ b/particles/string.c @@ -70,22 +70,10 @@ begin_expose(struct exposable *exposable) return exposable->width; } -static inline pixman_color_t -color_hex_to_pixman_with_alpha(uint32_t color, uint16_t alpha) -{ - int alpha_div = 0xffff / alpha; - return (pixman_color_t){ - .red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) / alpha_div, - .green = ((color >> 8 & 0xff) | (color >> 0 & 0xff00)) / alpha_div, - .blue = ((color >> 0 & 0xff) | (color << 8 & 0xff00)) / alpha_div, - .alpha = alpha, - }; -} - static void -expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) +expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height) { - exposable_render_deco(exposable, cr, x, y, height); + exposable_render_deco(exposable, pix, x, y, height); const struct eprivate *e = exposable->private; const struct font *font = exposable->particle->font; @@ -112,24 +100,6 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) (double)(height + font->fextents.ascent + font->fextents.descent) / 2.0 - (font->fextents.descent > 0 ? font->fextents.descent : 0); - /* TODO: get rid of cairo?... */ - cairo_surface_t *surf = cairo_get_target(cr); - cairo_surface_flush(surf); - - pixman_image_t *pix = pixman_image_create_bits_no_clear( - PIXMAN_a8r8g8b8, - cairo_image_surface_get_width(surf), - cairo_image_surface_get_height(surf), - (uint32_t *)cairo_image_surface_get_data(surf), - cairo_image_surface_get_stride(surf)); - - uint32_t hex_color = - (uint32_t)(uint8_t)(exposable->particle->foreground.red * 255) << 16 | - (uint32_t)(uint8_t)(exposable->particle->foreground.green * 255) << 8 | - (uint32_t)(uint8_t)(exposable->particle->foreground.blue * 255) << 0; - uint16_t alpha = exposable->particle->foreground.alpha * 65535; - pixman_color_t fg = color_hex_to_pixman_with_alpha(hex_color, alpha); - x += exposable->particle->left_margin; /* Loop glyphs and render them, one by one */ @@ -145,7 +115,7 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) glyph->width, glyph->height); } else { /* Glyph surface is an alpha mask */ - pixman_image_t *src = pixman_image_create_solid_fill(&fg); + pixman_image_t *src = pixman_image_create_solid_fill(&exposable->particle->foreground); pixman_image_composite32( PIXMAN_OP_OVER, src, glyph->pix, pix, 0, 0, 0, 0, x + glyph->x, baseline - glyph->y, @@ -155,9 +125,6 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) x += glyph->x_advance; } - - pixman_image_unref(pix); - cairo_surface_mark_dirty(surf); } static struct exposable *