icons: Remove caching

This commit is contained in:
Dorota Czaplejewicz
2019-10-25 15:43:04 +00:00
parent 63e55ff5c4
commit 01fe433612
2 changed files with 18 additions and 28 deletions

View File

@ -240,7 +240,7 @@ static void render_button_in_context(EekRenderer *self,
if (icon_name) { if (icon_name) {
gint scale = priv->scale_factor; gint scale = priv->scale_factor;
cairo_surface_t *icon_surface = cairo_surface_t *icon_surface =
eek_renderer_get_icon_surface (self, icon_name, 16 / priv->scale, eek_renderer_get_icon_surface (icon_name, 16 / priv->scale,
scale); scale);
if (icon_surface) { if (icon_surface) {
gint width = cairo_image_surface_get_width (icon_surface); gint width = cairo_image_surface_get_width (icon_surface);
@ -258,6 +258,7 @@ static void render_button_in_context(EekRenderer *self,
foreground.blue, foreground.blue,
foreground.alpha); foreground.alpha);
cairo_mask_surface (cr, icon_surface, 0.0, 0.0); cairo_mask_surface (cr, icon_surface, 0.0, 0.0);
cairo_surface_destroy(icon_surface);
cairo_fill (cr); cairo_fill (cr);
cairo_restore (cr); cairo_restore (cr);
return; return;
@ -834,38 +835,28 @@ eek_renderer_create_pango_layout (EekRenderer *renderer)
return pango_layout_new (priv->pcontext); return pango_layout_new (priv->pcontext);
} }
/// Surfaces returned from this are cached and must not be freed
cairo_surface_t * cairo_surface_t *
eek_renderer_get_icon_surface (EekRenderer *renderer, eek_renderer_get_icon_surface (const gchar *icon_name,
const gchar *icon_name,
gint size, gint size,
gint scale) gint scale)
{ {
GError *error = NULL; GError *error = NULL;
cairo_surface_t *surface; cairo_surface_t *surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
icon_name,
size,
scale,
NULL,
0,
&error);
g_return_val_if_fail (EEK_IS_RENDERER(renderer), NULL); if (surface == NULL) {
g_warning ("can't get icon surface for %s: %s",
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer); icon_name,
error->message);
surface = g_hash_table_lookup (priv->icons, icon_name); g_error_free (error);
if (!surface) { return NULL;
surface = gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
icon_name,
size,
scale,
NULL,
0,
&error);
g_hash_table_insert (priv->icons, g_strdup(icon_name), surface);
if (surface == NULL) {
g_warning ("can't get icon surface for %s: %s",
icon_name,
error->message);
g_error_free (error);
return NULL;
}
} }
return surface; return surface;
} }

View File

@ -82,8 +82,7 @@ void eek_renderer_render_button (EekRenderer *renderer,
gdouble scale, gdouble scale,
gboolean rotate); gboolean rotate);
cairo_surface_t *eek_renderer_get_icon_surface(EekRenderer *renderer, cairo_surface_t *eek_renderer_get_icon_surface(const gchar *icon_name,
const gchar *icon_name,
gint size, gint size,
gint scale); gint scale);