From 795e9ebbacf1f70aa1861073f1e600ee25d57879 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 4 Jul 2009 14:16:47 +0200 Subject: Only open the default font once, then ref it. As suggested in #3622, we don't need to open the default font for every place that wasn't specified in the theme. Solved a bit differently than the patch given there. --- render/theme.c | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'render') diff --git a/render/theme.c b/render/theme.c index d040c171..0882637a 100644 --- a/render/theme.c +++ b/render/theme.c @@ -46,6 +46,22 @@ static int parse_inline_number(const char *p); static RrPixel32* read_c_image(gint width, gint height, const guint8 *data); static void set_default_appearance(RrAppearance *a); +static RrFont *get_font(RrFont *target, RrFont **default_font, const RrInstance *inst) +{ + if (target) { + RrFontRef(target); + return target; + } else { + /* Only load the default font once */ + if (*default_font) { + RrFontRef(*default_font); + } else { + *default_font = RrFontOpenDefault(inst); + } + return *default_font; + } +} + RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, gboolean allow_fallback, RrFont *active_window_font, RrFont *inactive_window_font, @@ -56,6 +72,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, RrJustify winjust, mtitlejust; gchar *str; RrTheme *theme; + RrFont *default_font = NULL; gchar *path; gboolean userdef; @@ -130,17 +147,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, theme->osd_unhilite_fg = RrAppearanceNew(inst, 0); /* load the font stuff */ - if (active_window_font) { - theme->win_font_focused = active_window_font; - RrFontRef(active_window_font); - } else - theme->win_font_focused = RrFontOpenDefault(inst); - - if (inactive_window_font) { - theme->win_font_unfocused = inactive_window_font; - RrFontRef(inactive_window_font); - } else - theme->win_font_unfocused = RrFontOpenDefault(inst); + theme->win_font_focused = get_font(active_window_font, &default_font, inst); + theme->win_font_unfocused = get_font(inactive_window_font, &default_font, inst); winjust = RR_JUSTIFY_LEFT; if (read_string(db, "window.label.text.justify", &str)) { @@ -150,11 +158,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, winjust = RR_JUSTIFY_CENTER; } - if (menu_title_font) { - theme->menu_title_font = menu_title_font; - RrFontRef(menu_title_font); - } else - theme->menu_title_font = RrFontOpenDefault(inst); + theme->menu_title_font = get_font(menu_title_font, &default_font, inst); mtitlejust = RR_JUSTIFY_LEFT; if (read_string(db, "menu.title.text.justify", &str)) { @@ -164,17 +168,9 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name, mtitlejust = RR_JUSTIFY_CENTER; } - if (menu_item_font) { - theme->menu_font = menu_item_font; - RrFontRef(menu_item_font); - } else - theme->menu_font = RrFontOpenDefault(inst); - - if (osd_font) { - theme->osd_font = osd_font; - RrFontRef(osd_font); - } else - theme->osd_font = RrFontOpenDefault(inst); + theme->menu_font = get_font(menu_item_font, &default_font, inst); + + theme->osd_font = get_font(osd_font, &default_font, inst); /* load direct dimensions */ if ((!read_int(db, "menu.overlap.x", &theme->menu_overlap_x) && -- cgit v1.2.3 From 18a2bc6da55f1f065bcffdf1c3229d0f2fc7040c Mon Sep 17 00:00:00 2001 From: Reilly Grant Date: Sat, 4 Jul 2009 15:06:55 +0200 Subject: Fix memory corruption when y2sz is 0. data is incremented one too many times when y2sz is zero, leading to memory corruption. [ also changed % 2 to & 1 -- Mikael ] --- render/gradient.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'render') diff --git a/render/gradient.c b/render/gradient.c index 8b6850f0..60a0a555 100644 --- a/render/gradient.c +++ b/render/gradient.c @@ -507,11 +507,11 @@ static void gradient_splitvertical(RrAppearance *a, gint w, gint h) */ if (h <= 5) { y1sz = MAX(h/2, 0); - y2sz = (h < 3 ? 0 : h % 2); + y2sz = (h < 3) ? 0 : (h & 1); y3sz = MAX(h/2, 1); } else { - y1sz = h/2 - (1 - (h % 2)); + y1sz = h/2 - (1 - (h & 1)); y2sz = 1; y3sz = h/2; } @@ -534,13 +534,15 @@ static void gradient_splitvertical(RrAppearance *a, gint w, gint h) } *data = COLOR(y1); data += w; - for (y2 = y2sz-1; y2 > 0; --y2) { + if (y2sz) { + for (y2 = y2sz-1; y2 > 0; --y2) { + *data = COLOR(y2); + data += w; + NEXT(y2); + } *data = COLOR(y2); data += w; - NEXT(y2); } - *data = COLOR(y2); - data += w; for (y3 = y3sz-1; y3 > 0; --y3) { *data = COLOR(y3); data += w; -- cgit v1.2.3