[gtk+/wip/window-scales] GtkIconTheme: load_pattern -> load_surface
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/window-scales] GtkIconTheme: load_pattern -> load_surface
- Date: Tue, 2 Jul 2013 15:07:34 +0000 (UTC)
commit 2d850b0d0372c4ec817c2c41494c04318acef3c4
Author: Alexander Larsson <alexl redhat com>
Date: Tue Jul 2 16:54:05 2013 +0200
GtkIconTheme: load_pattern -> load_surface
We use cairo_surface_t instead of cairo_pattern_t, and
we use device-scale to handle scaling.
gtk/gtkfilechooserbutton.c | 55 ++++++++++++++++++++++++++++++-------------
gtk/gtkfilesystem.c | 11 +++++++-
gtk/gtkicontheme.c | 41 ++++++++++++--------------------
gtk/gtkicontheme.h | 4 +-
gtk/gtkstylecontext.h | 4 +-
5 files changed, 67 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index e1288b1..ec98043 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -1398,6 +1398,7 @@ change_icon_theme (GtkFileChooserButton *button)
do
{
+ cairo_surface_t *surface = NULL;
cairo_pattern_t *pattern = NULL;
gchar type;
gpointer data;
@@ -1438,16 +1439,20 @@ change_icon_theme (GtkFileChooserButton *button)
pattern = NULL;
}
else
- /* Don't call get_info for remote paths to avoid latency and
- * auth dialogs.
- * If we switch to a better bookmarks file format (XBEL), we
- * should use mime info to get a better icon.
- */
- pattern = gtk_icon_theme_load_pattern (theme, "folder-remote",
- priv->icon_size,
- gtk_widget_get_scale_factor (GTK_WIDGET (button)),
- gtk_widget_get_window (GTK_WIDGET (button)),
- 0, NULL);
+ {
+ /* Don't call get_info for remote paths to avoid latency and
+ * auth dialogs.
+ * If we switch to a better bookmarks file format (XBEL), we
+ * should use mime info to get a better icon.
+ */
+ surface = gtk_icon_theme_load_surface (theme, "folder-remote",
+ priv->icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (button)),
+ gtk_widget_get_window (GTK_WIDGET (button)),
+ 0, NULL);
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_surface_destroy (surface);
+ }
}
break;
case ROW_TYPE_VOLUME:
@@ -1974,7 +1979,8 @@ model_add_bookmarks (GtkFileChooserButton *button,
{
gchar *label;
GtkIconTheme *icon_theme;
- cairo_pattern_t *pattern;
+ cairo_pattern_t *pattern = NULL;
+ cairo_surface_t *surface = NULL;
if (local_only)
continue;
@@ -1989,11 +1995,13 @@ model_add_bookmarks (GtkFileChooserButton *button,
label = _gtk_file_chooser_label_for_file (file);
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
- pattern = gtk_icon_theme_load_pattern (icon_theme, "folder-remote",
+ surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote",
button->priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_surface_destroy (surface);
gtk_list_store_insert (store, &iter, pos);
gtk_list_store_set (store, &iter,
@@ -2084,7 +2092,8 @@ model_update_current_folder (GtkFileChooserButton *button,
{
gchar *label;
GtkIconTheme *icon_theme;
- cairo_pattern_t *pattern;
+ cairo_pattern_t *pattern = NULL;
+ cairo_surface_t *surface;
/* Don't call get_info for remote paths to avoid latency and
* auth dialogs.
@@ -2098,17 +2107,22 @@ model_update_current_folder (GtkFileChooserButton *button,
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (button)));
if (g_file_is_native (file))
- pattern = gtk_icon_theme_load_pattern (icon_theme, "folder",
+ surface = gtk_icon_theme_load_surface (icon_theme, "folder",
button->priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
else
- pattern = gtk_icon_theme_load_pattern (icon_theme, "folder-remote",
+ surface = gtk_icon_theme_load_surface (icon_theme, "folder-remote",
button->priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
+ if (surface)
+ {
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_surface_destroy (surface);
+ }
gtk_list_store_set (store, &iter,
ICON_COLUMN, pattern,
@@ -2548,15 +2562,22 @@ update_label_and_image (GtkFileChooserButton *button)
}
else
{
- cairo_pattern_t *pattern;
+ cairo_pattern_t *pattern = NULL;
+ cairo_surface_t *surface;
label_text = _gtk_bookmarks_manager_get_bookmark_label (button->priv->bookmarks_manager, file);
- pattern = gtk_icon_theme_load_pattern (get_icon_theme (GTK_WIDGET (priv->image)),
+ surface = gtk_icon_theme_load_surface (get_icon_theme (GTK_WIDGET (priv->image)),
"text-x-generic",
priv->icon_size,
gtk_widget_get_scale_factor (GTK_WIDGET (button)),
gtk_widget_get_window (GTK_WIDGET (button)),
0, NULL);
+ if (surface)
+ {
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_surface_destroy (surface);
+ }
+
gtk_image_set_from_pattern (GTK_IMAGE (priv->image), pattern);
if (pattern)
cairo_pattern_destroy (pattern);
diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c
index 1e4308b..3ef5076 100644
--- a/gtk/gtkfilesystem.c
+++ b/gtk/gtkfilesystem.c
@@ -718,7 +718,8 @@ get_pattern_from_gicon (GIcon *icon,
GdkScreen *screen;
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
- cairo_pattern_t *pattern;
+ cairo_pattern_t *pattern = NULL;
+ cairo_surface_t *surface;
screen = gtk_widget_get_screen (GTK_WIDGET (widget));
icon_theme = gtk_icon_theme_get_for_screen (screen);
@@ -732,8 +733,14 @@ get_pattern_from_gicon (GIcon *icon,
if (!icon_info)
return NULL;
- pattern = gtk_icon_info_load_pattern (icon_info,
+ surface = gtk_icon_info_load_surface (icon_info,
gtk_widget_get_window (widget), error);
+ if (surface)
+ {
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_surface_destroy (surface);
+ }
+
g_object_unref (icon_info);
return pattern;
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index ffcbd57..e88d519 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -2081,7 +2081,7 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
}
/**
- * gtk_icon_theme_load_pattern:
+ * gtk_icon_theme_load_surface:
* @icon_theme: a #GtkIconTheme
* @icon_name: the name of the icon to lookup
* @size: the desired icon size. The resulting icon may not be
@@ -2093,10 +2093,10 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
* or %NULL.
*
* Looks up an icon in an icon theme for a particular window scale,
- * scales it to the given size and renders it into a cairo pattern. This is a
+ * scales it to the given size and renders it into a cairo surface. This is a
* convenience function; if more details about the icon are needed,
* use gtk_icon_theme_lookup_icon() followed by
- * gtk_icon_info_load_pattern().
+ * gtk_icon_info_load_surface().
*
* Note that you probably want to listen for icon theme changes and
* update the icon. This is usually done by connecting to the
@@ -2104,13 +2104,13 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
*
* Return value: (transfer full): the rendered icon; this may be a
* newly created icon or a new reference to an internal icon, so
- * you must not modify the icon. Use cairo_pattern_destroy() to release
+ * you must not modify the icon. Use cairo_surface_destroy() to release
* your reference to the icon. %NULL if the icon isn't found.
*
* Since: 3.10
**/
-cairo_pattern_t *
-gtk_icon_theme_load_pattern (GtkIconTheme *icon_theme,
+cairo_surface_t *
+gtk_icon_theme_load_surface (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
gint scale,
@@ -2119,7 +2119,7 @@ gtk_icon_theme_load_pattern (GtkIconTheme *icon_theme,
GError **error)
{
GtkIconInfo *icon_info;
- cairo_pattern_t *pattern = NULL;
+ cairo_surface_t *surface = NULL;
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
g_return_val_if_fail (icon_name != NULL, NULL);
@@ -2137,10 +2137,10 @@ gtk_icon_theme_load_pattern (GtkIconTheme *icon_theme,
return NULL;
}
- pattern = gtk_icon_info_load_pattern (icon_info, for_window, error);
+ surface = gtk_icon_info_load_surface (icon_info, for_window, error);
g_object_unref (icon_info);
- return pattern;
+ return surface;
}
/**
@@ -3866,7 +3866,7 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
}
/**
- * gtk_icon_info_load_pattern:
+ * gtk_icon_info_load_surface:
* @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
* @for_window: (allow-none): #GdkWindow to optimize drawing for, or %NULL
* @error: (allow-none): location to store error information on failure,
@@ -3875,7 +3875,7 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
* Renders an icon previously looked up in an icon theme using
* gtk_icon_theme_lookup_icon(); the size will be based on the size
* passed to gtk_icon_theme_lookup_icon(). Note that the resulting
- * pattern may not be exactly this size; an icon theme may have icons
+ * surface may not be exactly this size; an icon theme may have icons
* that differ slightly from their nominal sizes, and in addition GTK+
* will avoid scaling icons that it considers sufficiently close to the
* requested size or for which the source image would have to be scaled
@@ -3886,20 +3886,18 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
*
* Return value: (transfer full): the rendered icon; this may be a newly
* created icon or a new reference to an internal icon, so you must
- * not modify the icon. Use cairo_pattern_destroy() to release your reference
+ * not modify the icon. Use cairo_surface_destroy() to release your reference
* to the icon.
*
* Since: 3.10
**/
-cairo_pattern_t *
-gtk_icon_info_load_pattern (GtkIconInfo *icon_info,
+cairo_surface_t *
+gtk_icon_info_load_surface (GtkIconInfo *icon_info,
GdkWindow *for_window,
GError **error)
{
GdkPixbuf *pixbuf;
cairo_surface_t *surface;
- cairo_pattern_t *pattern;
- cairo_matrix_t matrix;
g_return_val_if_fail (icon_info != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -3909,17 +3907,10 @@ gtk_icon_info_load_pattern (GtkIconInfo *icon_info,
if (pixbuf == NULL)
return NULL;
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, for_window);
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, icon_info->desired_scale, for_window);
g_object_unref (pixbuf);
- pattern = cairo_pattern_create_for_surface (surface);
- cairo_surface_destroy (surface);
- cairo_matrix_init_scale (&matrix,
- icon_info->desired_scale,
- icon_info->desired_scale);
- cairo_pattern_set_matrix (pattern, &matrix);
-
- return pattern;
+ return surface;
}
static void
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index 9109fe9..8afa5ee 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -211,7 +211,7 @@ GdkPixbuf * gtk_icon_theme_load_icon_for_scale (GtkIconTheme
GtkIconLookupFlags flags,
GError **error);
GDK_AVAILABLE_IN_3_10
-cairo_pattern_t * gtk_icon_theme_load_pattern (GtkIconTheme *icon_theme,
+cairo_surface_t * gtk_icon_theme_load_surface (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
gint scale,
@@ -270,7 +270,7 @@ GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info,
GError **error);
GDK_AVAILABLE_IN_3_10
-cairo_pattern_t * gtk_icon_info_load_pattern (GtkIconInfo *icon_info,
+cairo_surface_t * gtk_icon_info_load_surface (GtkIconInfo *icon_info,
GdkWindow *for_window,
GError **error);
GDK_AVAILABLE_IN_3_8
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index cd7b040..69d347a 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -886,8 +886,8 @@ GdkPixbuf * gtk_icon_set_render_icon_pixbuf (GtkIconSet *icon_set,
GtkStyleContext *context,
GtkIconSize size);
GDK_AVAILABLE_IN_3_10
-cairo_pattern_t *
-gtk_icon_set_render_icon_pattern (GtkIconSet *icon_set,
+cairo_surface_t *
+gtk_icon_set_render_icon_surface (GtkIconSet *icon_set,
GtkStyleContext *context,
GtkIconSize size,
int scale,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]