From 4a837b0c721c9680d8fc88d49d6c1805e279f284 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 26 Apr 2022 01:19:56 +0000 Subject: [PATCH] Cache relief colors on Haiku since their computation is expensive * src/haikufns.c (haiku_create_frame, haiku_create_tip_frame): Clear `relief_background'. * src/haikuterm.c (haiku_calculate_relief_colors): Cache relief colors for each frame. * src/haikuterm.h (struct haiku_output): New fields for caching the last relief color. --- src/haikufns.c | 2 ++ src/haikuterm.c | 19 +++++++++++++++---- src/haikuterm.h | 11 +++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/haikufns.c b/src/haikufns.c index 4f4979fe094..ae0f442a21c 100644 --- a/src/haikufns.c +++ b/src/haikufns.c @@ -700,6 +700,7 @@ haiku_create_frame (Lisp_Object parms) f->output_method = output_haiku; f->output_data.haiku = xzalloc (sizeof *f->output_data.haiku); f->output_data.haiku->wait_for_event_type = -1; + f->output_data.haiku->relief_background = -1; fset_icon_name (f, gui_display_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title", @@ -1015,6 +1016,7 @@ haiku_create_tip_frame (Lisp_Object parms) f->output_method = output_haiku; f->output_data.haiku = xzalloc (sizeof *f->output_data.haiku); f->output_data.haiku->wait_for_event_type = -1; + f->output_data.haiku->relief_background = -1; f->tooltip = true; fset_icon_name (f, Qnil); diff --git a/src/haikuterm.c b/src/haikuterm.c index f81efbdcbb7..86266424c41 100644 --- a/src/haikuterm.c +++ b/src/haikuterm.c @@ -623,17 +623,28 @@ haiku_calculate_relief_colors (struct glyph_string *s, uint32_t *rgbout_w, struct face *face = s->face; double h, cs, l; uint32_t rgbin; + struct haiku_output *di; - prepare_face_for_display (s->f, s->face); rgbin = (face->use_box_color_for_shadows_p ? face->box_color : face->background); + di = FRAME_OUTPUT_DATA (s->f); if (s->hl == DRAW_CURSOR) rgbin = FRAME_CURSOR_COLOR (s->f).pixel; - rgb_color_hsl (rgbin, &h, &cs, &l); - hsl_color_rgb (h, cs, fmin (1.0, fmax (0.2, l) * 0.6), rgbout_b); - hsl_color_rgb (h, cs, fmin (1.0, fmax (0.2, l) * 1.2), rgbout_w); + if (di->relief_background != rgbin) + { + di->relief_background = rgbin & 0xffffffff; + + rgb_color_hsl (rgbin, &h, &cs, &l); + hsl_color_rgb (h, cs, fmin (1.0, fmax (0.2, l) * 0.6), + &di->black_relief_pixel); + hsl_color_rgb (h, cs, fmin (1.0, fmax (0.2, l) * 1.2), + &di->white_relief_pixel); + } + + *rgbout_w = di->white_relief_pixel; + *rgbout_b = di->black_relief_pixel; } static void diff --git a/src/haikuterm.h b/src/haikuterm.h index d20d491838f..30b474b1e1d 100644 --- a/src/haikuterm.h +++ b/src/haikuterm.h @@ -181,6 +181,17 @@ struct haiku_output /* The type of any event that's being waited for. */ int wait_for_event_type; + + /* The "dark" color of the current relief. */ + uint32_t black_relief_pixel; + + /* The "light" color of the current relief. */ + uint32_t white_relief_pixel; + + /* The background for which the relief colors above were computed. + They are changed only when a different background is involved. + -1 means no color has been computed. */ + long relief_background; }; struct x_output -- 2.39.2