[gtk+/wip/window-scales] filesystem: Render to surfaces instead of patterns



commit a35db35996fa93e5422e4c35a3541a0386e39ad6
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Jul 2 17:06:44 2013 +0200

    filesystem: Render to surfaces instead of patterns

 gtk/gtkfilechooserbutton.c |   83 ++++++++++++++++++++++++++++++++++----------
 gtk/gtkfilesystem.c        |   43 ++++++++---------------
 gtk/gtkfilesystem.h        |    4 +-
 gtk/gtkpathbar.c           |   26 ++++++++++---
 4 files changed, 101 insertions(+), 55 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index ec98043..a32c47f 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -1321,7 +1321,8 @@ change_icon_theme_get_info_cb (GCancellable *cancellable,
                               gpointer      user_data)
 {
   gboolean cancelled = g_cancellable_is_cancelled (cancellable);
-  cairo_pattern_t *pattern;
+  cairo_pattern_t *pattern = NULL;
+  cairo_surface_t *surface;
   struct ChangeIconThemeData *data = user_data;
 
   if (!g_slist_find (data->button->priv->change_icon_theme_cancellables, cancellable))
@@ -1333,7 +1334,12 @@ change_icon_theme_get_info_cb (GCancellable *cancellable,
   if (cancelled || error)
     goto out;
 
-  pattern = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+  surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+  if (surface)
+    {
+      pattern = cairo_pattern_create_for_surface (surface);
+      cairo_surface_destroy (surface);
+    }
 
   if (pattern)
     {
@@ -1457,10 +1463,18 @@ change_icon_theme (GtkFileChooserButton *button)
          break;
        case ROW_TYPE_VOLUME:
          if (data)
-           pattern = _gtk_file_system_volume_render_icon (data,
-                                                          GTK_WIDGET (button),
-                                                          priv->icon_size,
-                                                          NULL);
+            {
+              surface = _gtk_file_system_volume_render_icon (data,
+                                                             GTK_WIDGET (button),
+                                                             priv->icon_size,
+                                                             NULL);
+              if (surface)
+                {
+                  pattern = cairo_pattern_create_for_surface (surface);
+                  cairo_surface_destroy (surface);
+                }
+            }
+
          break;
        default:
          continue;
@@ -1534,7 +1548,8 @@ set_info_get_info_cb (GCancellable *cancellable,
                      gpointer      callback_data)
 {
   gboolean cancelled = g_cancellable_is_cancelled (cancellable);
-  cairo_pattern_t *pattern;
+  cairo_pattern_t *pattern = NULL;
+  cairo_surface_t *surface;
   GtkTreePath *path;
   GtkTreeIter iter;
   GCancellable *model_cancellable = NULL;
@@ -1568,7 +1583,12 @@ set_info_get_info_cb (GCancellable *cancellable,
     /* There was an error, leave the fallback name in there */
     goto out;
 
-  pattern = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+  surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+  if (surface)
+    {
+      pattern = cairo_pattern_create_for_surface (surface);
+      cairo_surface_destroy (surface);
+    }
 
   if (!data->label)
     data->label = g_strdup (g_file_info_get_display_name (info));
@@ -1724,7 +1744,8 @@ model_add_special_get_info_cb (GCancellable *cancellable,
   gboolean cancelled = g_cancellable_is_cancelled (cancellable);
   GtkTreeIter iter;
   GtkTreePath *path;
-  cairo_pattern_t *pattern;
+  cairo_pattern_t *pattern = NULL;
+  cairo_surface_t *surface;
   GCancellable *model_cancellable = NULL;
   struct ChangeIconThemeData *data = user_data;
   gchar *name;
@@ -1754,7 +1775,12 @@ model_add_special_get_info_cb (GCancellable *cancellable,
   if (cancelled || error)
     goto out;
 
-  pattern = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+  surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->button), data->button->priv->icon_size);
+  if (surface)
+    {
+      pattern = cairo_pattern_create_for_surface (surface);
+      cairo_surface_destroy (surface);
+    }
 
   if (pattern)
     {
@@ -1889,7 +1915,8 @@ model_add_volumes (GtkFileChooserButton *button,
     {
       GtkFileSystemVolume *volume;
       GtkTreeIter iter;
-      cairo_pattern_t *pattern;
+      cairo_pattern_t *pattern = NULL;
+      cairo_surface_t *surface;
       gchar *display_name;
 
       volume = l->data;
@@ -1914,10 +1941,15 @@ model_add_volumes (GtkFileChooserButton *button,
             }
         }
 
-      pattern = _gtk_file_system_volume_render_icon (volume,
-                                                    GTK_WIDGET (button),
-                                                    button->priv->icon_size,
-                                                    NULL);
+      surface = _gtk_file_system_volume_render_icon (volume,
+                                                     GTK_WIDGET (button),
+                                                     button->priv->icon_size,
+                                                     NULL);
+      if (surface)
+        {
+          pattern = cairo_pattern_create_for_surface (surface);
+          cairo_surface_destroy (surface);
+        }
       display_name = _gtk_file_system_volume_get_display_name (volume);
 
       gtk_list_store_insert (store, &iter, pos);
@@ -2470,7 +2502,8 @@ update_label_get_info_cb (GCancellable *cancellable,
                          gpointer      data)
 {
   gboolean cancelled = g_cancellable_is_cancelled (cancellable);
-  cairo_pattern_t *pattern;
+  cairo_pattern_t *pattern = NULL;
+  cairo_surface_t *surface;
   GtkFileChooserButton *button = data;
   GtkFileChooserButtonPrivate *priv = button->priv;
 
@@ -2484,7 +2517,12 @@ update_label_get_info_cb (GCancellable *cancellable,
 
   gtk_label_set_text (GTK_LABEL (priv->label), g_file_info_get_display_name (info));
 
-  pattern = _gtk_file_info_render_icon (info, GTK_WIDGET (priv->image), priv->icon_size);
+  surface = _gtk_file_info_render_icon (info, GTK_WIDGET (priv->image), priv->icon_size);
+  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)
@@ -2528,13 +2566,20 @@ update_label_and_image (GtkFileChooserButton *button)
           base_file = _gtk_file_system_volume_get_root (volume);
           if (base_file && g_file_equal (base_file, file))
             {
-              cairo_pattern_t *pattern;
+              cairo_pattern_t *pattern = NULL;
+              cairo_surface_t *surface;
 
               label_text = _gtk_file_system_volume_get_display_name (volume);
-              pattern = _gtk_file_system_volume_render_icon (volume,
+              surface = _gtk_file_system_volume_render_icon (volume,
                                                             GTK_WIDGET (button),
                                                             priv->icon_size,
                                                             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 3ef5076..f1e041d 100644
--- a/gtk/gtkfilesystem.c
+++ b/gtk/gtkfilesystem.c
@@ -709,8 +709,8 @@ _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume)
   return file;
 }
 
-static cairo_pattern_t *
-get_pattern_from_gicon (GIcon      *icon,
+static cairo_surface_t *
+get_surface_from_gicon (GIcon      *icon,
                        GtkWidget  *widget,
                        gint        icon_size,
                        GError    **error)
@@ -718,7 +718,6 @@ get_pattern_from_gicon (GIcon      *icon,
   GdkScreen *screen;
   GtkIconTheme *icon_theme;
   GtkIconInfo *icon_info;
-  cairo_pattern_t *pattern = NULL;
   cairo_surface_t *surface;
 
   screen = gtk_widget_get_screen (GTK_WIDGET (widget));
@@ -735,25 +734,20 @@ get_pattern_from_gicon (GIcon      *icon,
 
   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;
+  return surface;
 }
 
-cairo_pattern_t *
+cairo_surface_t *
 _gtk_file_system_volume_render_icon (GtkFileSystemVolume  *volume,
                                     GtkWidget            *widget,
                                     gint                  icon_size,
                                     GError              **error)
 {
   GIcon *icon = NULL;
-  cairo_pattern_t *pattern;
+  cairo_surface_t *surface;
 
   DEBUG ("volume_get_icon_name");
 
@@ -769,11 +763,11 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume  *volume,
   if (!icon)
     return NULL;
 
-  pattern = get_pattern_from_gicon (icon, widget, icon_size, error);
+  surface = get_surface_from_gicon (icon, widget, icon_size, error);
 
   g_object_unref (icon);
 
-  return pattern;
+  return surface;
 }
 
 GtkFileSystemVolume *
@@ -804,17 +798,15 @@ _gtk_file_system_volume_unref (GtkFileSystemVolume *volume)
 }
 
 /* GFileInfo helper functions */
-cairo_pattern_t *
+cairo_surface_t *
 _gtk_file_info_render_icon (GFileInfo *info,
                            GtkWidget *widget,
                            gint       icon_size)
 {
   GIcon *icon;
   GdkPixbuf *pixbuf;
-  cairo_pattern_t *pattern = NULL;
   const gchar *thumbnail_path;
-  cairo_surface_t *surface;
-  cairo_matrix_t matrix;
+  cairo_surface_t *surface = NULL;
   int scale;
 
   thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
@@ -826,33 +818,28 @@ _gtk_file_info_render_icon (GFileInfo *info,
                                                 icon_size*scale, icon_size*scale,
                                                 NULL);
 
-      surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1,
+      surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale,
                                                       gtk_widget_get_window (widget));
       g_object_unref (pixbuf);
-      pattern = cairo_pattern_create_for_surface (surface);
-      cairo_surface_destroy (surface);
-      
-      cairo_matrix_init_scale (&matrix, scale, scale);
-      cairo_pattern_set_matrix (pattern, &matrix);
     }
 
-  if (!pattern)
+  if (!surface)
     {
       icon = g_file_info_get_icon (info);
 
       if (icon)
-       pattern = get_pattern_from_gicon (icon, widget, icon_size, NULL);
+       surface = get_surface_from_gicon (icon, widget, icon_size, NULL);
 
-      if (!pattern)
+      if (!surface)
        {
           /* Use general fallback for all files without icon */
          icon = g_themed_icon_new ("text-x-generic");
-         pattern = get_pattern_from_gicon (icon, widget, icon_size, NULL);
+         surface = get_surface_from_gicon (icon, widget, icon_size, NULL);
          g_object_unref (icon);
        }
     }
 
-  return pattern;
+  return surface;
 }
 
 gboolean
diff --git a/gtk/gtkfilesystem.h b/gtk/gtkfilesystem.h
index b49834b..1f38184 100644
--- a/gtk/gtkfilesystem.h
+++ b/gtk/gtkfilesystem.h
@@ -93,7 +93,7 @@ GtkFileSystemVolume * _gtk_file_system_get_volume_for_file (GtkFileSystem
 gchar *               _gtk_file_system_volume_get_display_name (GtkFileSystemVolume *volume);
 gboolean              _gtk_file_system_volume_is_mounted       (GtkFileSystemVolume *volume);
 GFile *               _gtk_file_system_volume_get_root         (GtkFileSystemVolume *volume);
-cairo_pattern_t *     _gtk_file_system_volume_render_icon      (GtkFileSystemVolume  *volume,
+cairo_surface_t *     _gtk_file_system_volume_render_icon      (GtkFileSystemVolume  *volume,
                                                                GtkWidget            *widget,
                                                                gint                  icon_size,
                                                                GError              **error);
@@ -102,7 +102,7 @@ GtkFileSystemVolume  *_gtk_file_system_volume_ref              (GtkFileSystemVol
 void                  _gtk_file_system_volume_unref            (GtkFileSystemVolume *volume);
 
 /* GFileInfo helper functions */
-cairo_pattern_t *     _gtk_file_info_render_icon (GFileInfo *info,
+cairo_surface_t *     _gtk_file_info_render_icon (GFileInfo *info,
                                                  GtkWidget *widget,
                                                  gint       icon_size);
 
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index e4f63cb..51135a2 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -1375,7 +1375,8 @@ set_button_image_get_info_cb (GCancellable *cancellable,
                              gpointer      user_data)
 {
   gboolean cancelled = g_cancellable_is_cancelled (cancellable);
-  cairo_pattern_t *pattern;
+  cairo_pattern_t *pattern = NULL;
+  cairo_surface_t *surface;
   struct SetButtonImageData *data = user_data;
 
   if (cancellable != data->button_data->cancellable)
@@ -1392,8 +1393,13 @@ set_button_image_get_info_cb (GCancellable *cancellable,
   if (cancelled || error)
     goto out;
 
-  pattern = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
+  surface = _gtk_file_info_render_icon (info, GTK_WIDGET (data->path_bar),
                                       data->path_bar->priv->icon_size);
+  if (surface)
+    {
+      pattern = cairo_pattern_create_for_surface (surface);
+      cairo_surface_destroy (surface);
+    }
   gtk_image_set_from_pattern (GTK_IMAGE (data->button_data->image), pattern);
 
   switch (data->button_data->type)
@@ -1427,6 +1433,8 @@ set_button_image (GtkPathBar *path_bar,
 {
   GtkFileSystemVolume *volume;
   struct SetButtonImageData *data;
+  cairo_pattern_t *pattern = NULL;
+  cairo_surface_t *surface;
 
   switch (button_data->type)
     {
@@ -1442,10 +1450,16 @@ set_button_image (GtkPathBar *path_bar,
       if (volume == NULL)
        return;
 
-      path_bar->priv->root_icon = _gtk_file_system_volume_render_icon (volume,
-                                                                GTK_WIDGET (path_bar),
-                                                                path_bar->priv->icon_size,
-                                                                NULL);
+      surface = _gtk_file_system_volume_render_icon (volume,
+                                                     GTK_WIDGET (path_bar),
+                                                     path_bar->priv->icon_size,
+                                                     NULL);
+      if (surface)
+        {
+          pattern = cairo_pattern_create_for_surface (surface);
+          cairo_surface_destroy (surface);
+        }
+      path_bar->priv->root_icon = pattern;
       _gtk_file_system_volume_unref (volume);
 
       gtk_image_set_from_pattern (GTK_IMAGE (button_data->image), path_bar->priv->root_icon);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]