[gtk: 7/40] icon theme: Add gtk_icon_info_download_texture() function
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 7/40] icon theme: Add gtk_icon_info_download_texture() function
- Date: Thu, 30 Jan 2020 17:31:44 +0000 (UTC)
commit 884e06ad372d6147145d83327d6aa56d01e851f9
Author: Alexander Larsson <alexl redhat com>
Date: Tue Jan 28 08:34:14 2020 +0100
icon theme: Add gtk_icon_info_download_texture() function
This returns a reference to the texture (if possible) and can be
used to get access to the pixels of the icon.
gtk/gtkicontheme.c | 36 ++++++++++++++++++++++++++----------
gtk/gtkicontheme.h | 5 +++++
2 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 01da64cc8f..768889bea1 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3832,20 +3832,36 @@ icon_info_ensure_scale_and_texture__locked (GtkIconInfo *icon_info)
return TRUE;
}
-static GdkTexture *
-icon_info_get_texture (GtkIconInfo *icon_info)
+GdkTexture *
+gtk_icon_info_download_texture (GtkIconInfo *self,
+ GError **error)
{
GdkTexture *texture = NULL;
- g_mutex_lock (&icon_info->cache_lock);
+ g_mutex_lock (&self->cache_lock);
- if (!icon_info->texture)
- icon_info_ensure_scale_and_texture__locked (icon_info);
+ if (!self->texture)
+ icon_info_ensure_scale_and_texture__locked (self);
- if (icon_info->texture)
- texture = g_object_ref (icon_info->texture);
+ if (self->texture)
+ texture = g_object_ref (self->texture);
+ else
+ {
+ if (self->load_error)
+ {
+ if (error)
+ *error = g_error_copy (self->load_error);
+ }
+ else
+ {
+ g_set_error_literal (error,
+ GTK_ICON_THEME_ERROR,
+ GTK_ICON_THEME_NOT_FOUND,
+ _("Failed to load icon"));
+ }
+ }
- g_mutex_unlock (&icon_info->cache_lock);
+ g_mutex_unlock (&self->cache_lock);
return texture;
}
@@ -3859,7 +3875,7 @@ icon_info_paintable_snapshot (GdkPaintable *paintable,
GtkIconInfo *icon_info = GTK_ICON_INFO (paintable);
GdkTexture *texture;
- texture = icon_info_get_texture (icon_info);
+ texture = gtk_icon_info_download_texture (icon_info, NULL);
if (texture)
{
if (icon_info->desired_scale != 1)
@@ -3890,7 +3906,7 @@ gtk_icon_info_snapshot_with_colors (GtkIconInfo *icon_info,
{
GdkTexture *texture;
- texture = icon_info_get_texture (icon_info);
+ texture = gtk_icon_info_download_texture (icon_info, NULL);
if (texture)
{
gboolean symbolic = gtk_icon_info_is_symbolic (icon_info);
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index 484d329439..dee4b114ca 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -213,6 +213,11 @@ GDK_AVAILABLE_IN_ALL
const gchar * gtk_icon_info_get_filename (GtkIconInfo *self);
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_info_is_symbolic (GtkIconInfo *self);
+GDK_AVAILABLE_IN_ALL
+GdkTexture * gtk_icon_info_download_texture (GtkIconInfo *self,
+ GError **error);
+
+GDK_AVAILABLE_IN_ALL
void gtk_icon_info_snapshot_with_colors (GtkIconInfo *icon_info,
GdkSnapshot *snapshot,
double width,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]