Compare commits

...

16 Commits

Author SHA1 Message Date
Timm Bäder
72d45ed43c icontheme: Avoid excessive icon_name_is_symbolic calls 2019-07-21 10:33:58 +02:00
Timm Bäder
8bd7283094 icontheme: Plug leak 2019-07-21 10:33:58 +02:00
Timm Bäder
6ec1824b96 icontheme: optimize icon_uri_is_symbolic as well 2019-07-21 10:33:58 +02:00
Timm Bäder
7bee0250f6 pixbufutils: Save a few temporary memory allocations 2019-07-21 10:33:58 +02:00
Timm Bäder
0246a49e76 icontheme: Use a GPtrArray for resource paths 2019-07-21 10:33:58 +02:00
Timm Bäder
f84ac56866 icontheme: Stop using GLists for icon theme directories 2019-07-21 10:33:58 +02:00
Timm Bäder
6c142d9469 icontheme: Remove priv pointer 2019-07-21 10:33:58 +02:00
Timm Bäder
7edc230c5a icontheme: Stop using GPtrArrays in choose_icon
We actually know the exact amount of new icon names we will have before.
2019-07-21 10:33:58 +02:00
Timm Bäder
3eab169327 main: Check if any debug flags are set in gtk_get_debug_flags()
We end up checking the debug flags for the default display, but that's
unnecessary if we know that no display has any debug flags set anyway.
2019-07-21 10:33:58 +02:00
Timm Bäder
efea47daf5 icontheme: Save the min_suffix for the min_dir
We already have to compute that value in the loop before, so just save
it.
2019-07-21 10:33:58 +02:00
Timm Bäder
cba0d6878a icontheme: Remove use_builtin parameter from theme_lookup_icon
Unused.
2019-07-21 10:33:58 +02:00
Timm Bäder
7c4b577bfe icontheme: Remove paramter from get_icon_suffix
Turns out nobody care about that one.
2019-07-21 10:33:58 +02:00
Timm Bäder
6c7f1b30f7 icontheme: Optimize icon_name_is_symbolic
We call this function *a lot* it's doing lots of unnecessary work inside
g_str_has_suffix. Get the icon name length only once instead and
open-code the suffix check.
2019-07-21 10:33:58 +02:00
Timm Bäder
da9c9079db icontheme: Avoid a g_strconcat in get_icon_suffix
We and up calling this code path over 7000 times on startup.
2019-07-21 10:33:58 +02:00
Timm Bäder
f9950ae50e gtkicontheme: Avoid a get_icon_flags call
We're only using the value of the first call at all if
symbolic_suffix & ICON_SUFFIX_PNG is FALSE.
2019-07-21 10:33:58 +02:00
Timm Bäder
bfd089baaa icontheme: Avoid some memory allocations
Pass the length of the icon list instead of NULL-terminating the array,
to avoid potentially re-allocating the entire GPtrArray we use as a
source for the icon names.
And choose a reasonable default size for the GPtrArrays.
2019-07-21 10:33:57 +02:00
4 changed files with 461 additions and 336 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -65,7 +65,7 @@ typedef struct _GtkIconTheme GtkIconTheme;
* text direction
* @GTK_ICON_LOOKUP_DIR_RTL: Try to load a variant of the icon for right-to-left
* text direction
*
*
* Used to specify options for gtk_icon_theme_lookup_icon()
*/
typedef enum
@@ -92,7 +92,7 @@ typedef enum
* GtkIconThemeError:
* @GTK_ICON_THEME_NOT_FOUND: The icon specified does not exist in the theme
* @GTK_ICON_THEME_FAILED: An unspecified error occurred.
*
*
* Error codes for GtkIconTheme operations.
**/
typedef enum {

View File

@@ -740,7 +740,10 @@ gtk_set_display_debug_flags (GdkDisplay *display,
guint
gtk_get_debug_flags (void)
{
return gtk_get_display_debug_flags (gdk_display_get_default ());
if (gtk_get_any_display_debug_flag_set ())
return gtk_get_display_debug_flags (gdk_display_get_default ());
return 0;
}
/**

View File

@@ -131,6 +131,40 @@ _gdk_pixbuf_new_from_resource_scaled (const gchar *resource_path,
return pixbuf;
}
/* rgba(255,255,255,1.0) */
#define MAX_RGBA_STRING_LENGTH (4 + 1 + (((3 + 1) * 3) + 3) + 1)
static inline void
rgba_to_string (const GdkRGBA *rgba,
char *buff)
{
/* gdk_rgba_to_string inlined in here for the alpha == 1 case,
* and g_strdup_printf replaced with g_snprintf */
if (rgba->alpha > 0.999)
{
g_snprintf (buff,
MAX_RGBA_STRING_LENGTH,
"rgb(%d,%d,%d)",
(int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.));
}
else
{
gchar alpha[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_formatd (alpha, G_ASCII_DTOSTR_BUF_SIZE, "%g", CLAMP (rgba->alpha, 0, 1));
g_snprintf (buff,
MAX_RGBA_STRING_LENGTH,
"rgba(%d,%d,%d,%s)",
(int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.),
alpha);
}
}
static GdkPixbuf *
load_symbolic_svg (const char *file_data,
gsize file_len,
@@ -145,21 +179,19 @@ load_symbolic_svg (const char *file_data,
{
GInputStream *stream;
GdkPixbuf *pixbuf;
gchar *css_fg;
gchar *css_success;
gchar *css_warning;
gchar *css_error;
gchar *data;
gchar *svg_width, *svg_height;
gchar *escaped_file_data;
char svg_width[32];
char svg_height[32];
char css_fg[MAX_RGBA_STRING_LENGTH];
char css_warning[MAX_RGBA_STRING_LENGTH];
char css_error[MAX_RGBA_STRING_LENGTH];
char css_success[MAX_RGBA_STRING_LENGTH];
css_fg = gdk_rgba_to_string (fg);
css_success = css_warning = css_error = NULL;
css_warning = gdk_rgba_to_string (warning_color);
css_error = gdk_rgba_to_string (error_color);
css_success = gdk_rgba_to_string (success_color);
rgba_to_string (fg, css_fg);
rgba_to_string (warning_color, css_warning);
rgba_to_string (error_color, css_error);
rgba_to_string (success_color, css_success);
/* Fetch size from the original icon */
stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL);
@@ -174,8 +206,8 @@ load_symbolic_svg (const char *file_data,
if (height == 0)
height = gdk_pixbuf_get_height (pixbuf) * scale;
svg_width = g_strdup_printf ("%d", gdk_pixbuf_get_width (pixbuf));
svg_height = g_strdup_printf ("%d", gdk_pixbuf_get_height (pixbuf));
g_snprintf (svg_width, 32, "%d", gdk_pixbuf_get_width (pixbuf));
g_snprintf (svg_height, 32, "%d", gdk_pixbuf_get_height (pixbuf));
g_object_unref (pixbuf);
escaped_file_data = g_base64_encode ((guchar *) file_data, file_len);
@@ -204,12 +236,6 @@ load_symbolic_svg (const char *file_data,
"</svg>",
NULL);
g_free (escaped_file_data);
g_free (css_fg);
g_free (css_warning);
g_free (css_error);
g_free (css_success);
g_free (svg_width);
g_free (svg_height);
stream = g_memory_input_stream_new_from_data (data, -1, g_free);
pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, width, height, TRUE, NULL, error);