[gtk+] mountoperation: Store icons as textures



commit 029165638b5468d58d6293154200d08eb37a54c8
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Nov 30 16:39:14 2017 -0500

    mountoperation: Store icons as textures
    
    This reduces the amount of pixbufs in this code.

 gtk/gtkmountoperation-stub.c   |    2 +-
 gtk/gtkmountoperation-x11.c    |   26 ++++++++++++++++----------
 gtk/gtkmountoperation.c        |   36 +++++++++++++++++-------------------
 gtk/gtkmountoperationprivate.h |    2 +-
 4 files changed, 35 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkmountoperation-stub.c b/gtk/gtkmountoperation-stub.c
index e053324..30ecb9d 100644
--- a/gtk/gtkmountoperation-stub.c
+++ b/gtk/gtkmountoperation-stub.c
@@ -47,7 +47,7 @@ _gtk_mount_operation_lookup_info (GtkMountOperationLookupContext *context,
                                   gint                            size_pixels,
                                   gchar                         **out_name,
                                   gchar                         **out_command_line,
-                                  GdkPixbuf                     **out_pixbuf)
+                                  GdkTexture                    **out_texture)
 {
   return FALSE;
 }
diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c
index cdc246f..562fa8d 100644
--- a/gtk/gtkmountoperation-x11.c
+++ b/gtk/gtkmountoperation-x11.c
@@ -407,7 +407,7 @@ free_pixels (guchar *pixels, gpointer data)
   g_free (pixels);
 }
 
-static GdkPixbuf*
+static GdkTexture *
 scaled_from_pixdata (guchar *pixdata,
                      int     w,
                      int     h,
@@ -416,6 +416,7 @@ scaled_from_pixdata (guchar *pixdata,
 {
   GdkPixbuf *src;
   GdkPixbuf *dest;
+  GdkTexture *ret;
 
   src = gdk_pixbuf_new_from_data (pixdata,
                                   GDK_COLORSPACE_RGB,
@@ -460,7 +461,11 @@ scaled_from_pixdata (guchar *pixdata,
       dest = src;
     }
 
-  return dest;
+  ret = gdk_texture_new_for_pixbuf (dest);
+
+  g_object_unref (dest);
+
+  return ret;
 }
 
 static gboolean
@@ -910,13 +915,13 @@ get_name_for_window_with_pid (GtkMountOperationLookupContext *context,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static GdkPixbuf *
-get_pixbuf_for_window_with_pid (GtkMountOperationLookupContext *context,
-                                GPid                            pid,
-                                gint                            size_pixels)
+static GdkTexture *
+get_texture_for_window_with_pid (GtkMountOperationLookupContext *context,
+                                 GPid                            pid,
+                                 gint                            size_pixels)
 {
   Window window;
-  GdkPixbuf *ret;
+  GdkTexture *ret;
 
   ret = NULL;
 
@@ -951,6 +956,7 @@ get_pixbuf_for_window_with_pid (GtkMountOperationLookupContext *context,
                          &pixdata))
         {
           /* steals pixdata */
+
           ret = scaled_from_pixdata (pixdata,
                                      width, height,
                                      size_pixels, size_pixels);
@@ -979,11 +985,11 @@ _gtk_mount_operation_lookup_info (GtkMountOperationLookupContext *context,
                                   gint                            size_pixels,
                                   gchar                         **out_name,
                                   gchar                         **out_command_line,
-                                  GdkPixbuf                     **out_pixbuf)
+                                  GdkTexture                    **out_texture)
 {
   g_return_val_if_fail (out_name != NULL && *out_name == NULL, FALSE);
   g_return_val_if_fail (out_command_line != NULL && *out_command_line == NULL, FALSE);
-  g_return_val_if_fail (out_pixbuf != NULL && *out_pixbuf == NULL, FALSE);
+  g_return_val_if_fail (out_texture != NULL && *out_texture == NULL, FALSE);
 
   /* We perform two different lookups for name and icon size.. this is
    * because we want the name from the window with WINDOWID and this
@@ -998,7 +1004,7 @@ _gtk_mount_operation_lookup_info (GtkMountOperationLookupContext *context,
 
   *out_name = get_name_for_window_with_pid (context, pid);
 
-  *out_pixbuf = get_pixbuf_for_window_with_pid (context, pid, size_pixels);
+  *out_texture = get_texture_for_window_with_pid (context, pid, size_pixels);
 
   /* if we didn't manage to find the name via X, fall back to the basename
    * of the first element of the command line and, for maximum geek-comfort,
diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c
index ebf3635..36dbd91 100644
--- a/gtk/gtkmountoperation.c
+++ b/gtk/gtkmountoperation.c
@@ -1061,19 +1061,19 @@ add_pid_to_process_list_store (GtkMountOperation              *mount_operation,
 {
   gchar *command_line;
   gchar *name;
-  GdkPixbuf *pixbuf;
+  GdkTexture *texture;
   gchar *markup;
   GtkTreeIter iter;
 
   name = NULL;
-  pixbuf = NULL;
+  texture = NULL;
   command_line = NULL;
   _gtk_mount_operation_lookup_info (lookup_context,
                                     pid,
                                     24,
                                     &name,
                                     &command_line,
-                                    &pixbuf);
+                                    &texture);
 
   if (name == NULL)
     name = g_strdup_printf (_("Unknown Application (PID %d)"), (int) (gssize) pid);
@@ -1081,17 +1081,17 @@ add_pid_to_process_list_store (GtkMountOperation              *mount_operation,
   if (command_line == NULL)
     command_line = g_strdup ("");
 
-  if (pixbuf == NULL)
+  if (texture == NULL)
     {
       GtkIconTheme *theme;
+      GtkIconInfo *info;
+
       theme = gtk_css_icon_theme_value_get_icon_theme
         (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET 
(mount_operation->priv->dialog)),
                                            GTK_CSS_PROPERTY_ICON_THEME));
-      pixbuf = gtk_icon_theme_load_icon (theme,
-                                         "application-x-executable",
-                                         24,
-                                         0,
-                                         NULL);
+      info = gtk_icon_theme_lookup_icon (theme, "application-x-executable", 24, 0);
+      texture = gtk_icon_info_load_texture (info);
+      g_object_unref (info);
     }
 
   markup = g_strdup_printf ("<b>%s</b>\n"
@@ -1101,13 +1101,13 @@ add_pid_to_process_list_store (GtkMountOperation              *mount_operation,
 
   gtk_list_store_append (list_store, &iter);
   gtk_list_store_set (list_store, &iter,
-                      0, pixbuf,
+                      0, texture,
                       1, markup,
                       2, pid,
                       -1);
 
-  if (pixbuf != NULL)
-    g_object_unref (pixbuf);
+  if (texture != NULL)
+    g_object_unref (texture);
   g_free (markup);
   g_free (name);
   g_free (command_line);
@@ -1415,7 +1415,8 @@ create_show_processes_dialog (GtkMountOperation *op,
   gtk_box_pack_start (GTK_BOX (vbox), label);
 
   /* First count the items in the list then
-   * add the buttons in reverse order */
+   * add the buttons in reverse order
+   */
 
   while (choices[len] != NULL)
     len++;
@@ -1433,16 +1434,13 @@ create_show_processes_dialog (GtkMountOperation *op,
     gtk_window_set_display (GTK_WINDOW (dialog), priv->display);
 
   tree_view = gtk_tree_view_new ();
-  /* TODO: should use EM's when gtk+ RI patches land */
-  gtk_widget_set_size_request (tree_view,
-                               300,
-                               120);
+  gtk_widget_set_size_request (tree_view, 300, 120);
 
   column = gtk_tree_view_column_new ();
   renderer = gtk_cell_renderer_pixbuf_new ();
   gtk_tree_view_column_pack_start (column, renderer, FALSE);
   gtk_tree_view_column_set_attributes (column, renderer,
-                                       "pixbuf", 0,
+                                       "texture", 0,
                                        NULL);
   renderer = gtk_cell_renderer_text_new ();
   g_object_set (renderer,
@@ -1474,7 +1472,7 @@ create_show_processes_dialog (GtkMountOperation *op,
                     op);
 
   list_store = gtk_list_store_new (3,
-                                   GDK_TYPE_PIXBUF,
+                                   GDK_TYPE_TEXTURE,
                                    G_TYPE_STRING,
                                    G_TYPE_INT);
 
diff --git a/gtk/gtkmountoperationprivate.h b/gtk/gtkmountoperationprivate.h
index 500d14d..40b63e9 100644
--- a/gtk/gtkmountoperationprivate.h
+++ b/gtk/gtkmountoperationprivate.h
@@ -40,7 +40,7 @@ gboolean _gtk_mount_operation_lookup_info         (GtkMountOperationLookupContex
                                                    gint                            size_pixels,
                                                    gchar                         **out_name,
                                                    gchar                         **out_command_line,
-                                                   GdkPixbuf                     **out_pixbuf);
+                                                   GdkTexture                    **out_texture);
 
 void     _gtk_mount_operation_lookup_context_free (GtkMountOperationLookupContext *context);
 


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