From 68132ab8fb66a0462b77304a5bbc9313f3dcb7bc Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Thu, 9 Jun 2022 17:34:13 +0100 Subject: Speed up Cairo initialisation. Rather than using cairo_paint() and re-drawing the middle of the window multiple times, use cairo_rectangle() + cairo_stroke(). This especially helps for large (e.g. fullscreen) windows. --- src/entry.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/entry.c') diff --git a/src/entry.c b/src/entry.c index eb58695..464c225 100644 --- a/src/entry.c +++ b/src/entry.c @@ -28,7 +28,10 @@ void entry_init(struct entry *entry, uint32_t width, uint32_t height, uint32_t s /* Draw the outer outline */ struct color color = entry->border.outline_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_paint(cr); + cairo_set_line_width(cr, 2 * entry->border.outline_width); + cairo_rectangle(cr, 0, 0, width, height); + cairo_stroke(cr); + /* Move and clip following draws to be within this outline */ cairo_translate( @@ -43,7 +46,9 @@ void entry_init(struct entry *entry, uint32_t width, uint32_t height, uint32_t s /* Draw the border */ color = entry->border.color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_paint(cr); + cairo_set_line_width(cr, 2 * entry->border.width); + cairo_rectangle(cr, 0, 0, width, height); + cairo_stroke(cr); /* Move and clip following draws to be within the border */ cairo_translate(cr, entry->border.width, entry->border.width); @@ -55,7 +60,9 @@ void entry_init(struct entry *entry, uint32_t width, uint32_t height, uint32_t s /* Draw the inner outline */ color = entry->border.outline_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_paint(cr); + cairo_set_line_width(cr, 2 * entry->border.outline_width); + cairo_rectangle(cr, 0, 0, width, height); + cairo_stroke(cr); /* Move and clip following draws to be within this outline */ cairo_translate( -- cgit v1.2.3