[gtk+] window: Make icons GdkTextures



commit 70846c85b32cd31c2c5adba301c24f9684ad7f60
Author: Benjamin Otte <otte redhat com>
Date:   Sat Nov 4 20:23:33 2017 +0100

    window: Make icons GdkTextures
    
    Cairo surfaces are bad, mkay?

 gdk/gdkwindow.c             |    6 +-
 gdk/win32/gdkwindow-win32.c |   40 +++----
 gdk/x11/gdkwindow-x11.c     |   91 ++++++-----------
 gtk/gtkheaderbar.c          |   12 +-
 gtk/gtkwindow.c             |  241 ++++++++++++++++++++-----------------------
 gtk/gtkwindow.h             |    6 +-
 gtk/gtkwindowprivate.h      |    5 +-
 7 files changed, 175 insertions(+), 226 deletions(-)
---
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index c7c2f40..6084576 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -6441,7 +6441,7 @@ gdk_window_get_event_compression (GdkWindow *window)
 /**
  * gdk_window_set_icon_list:
  * @window: The #GdkWindow toplevel window to set the icon of.
- * @surfaces: (transfer none) (element-type cairo_surface_t):
+ * @surfaces: (transfer none) (element-type GdkTexture):
  *     A list of image surfaces, of different sizes.
  *
  * Sets a list of icons for the window. One of these will be used
@@ -6456,9 +6456,9 @@ gdk_window_get_event_compression (GdkWindow *window)
  */
 void
 gdk_window_set_icon_list (GdkWindow *window,
-                          GList     *surfaces)
+                          GList     *textures)
 {
-  GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, surfaces);
+  GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, textures);
 }
 
 /**
diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c
index 97f86fa..24cd94e 100644
--- a/gdk/win32/gdkwindow-win32.c
+++ b/gdk/win32/gdkwindow-win32.c
@@ -2251,9 +2251,9 @@ gdk_win32_window_set_focus_on_map (GdkWindow *window,
 
 static void
 gdk_win32_window_set_icon_list (GdkWindow *window,
-                                GList     *surfaces)
+                                GList     *textures)
 {
-  cairo_surface_t *surface, *big_surface, *small_surface;
+  GdkTexture *big_texture, *small_texture;
   GdkPixbuf *big_pixbuf, *small_pixbuf;
   gint big_diff, small_diff;
   gint big_w, big_h, small_w, small_h;
@@ -2264,7 +2264,7 @@ gdk_win32_window_set_icon_list (GdkWindow *window,
 
   g_return_if_fail (GDK_IS_WINDOW (window));
 
-  if (GDK_WINDOW_DESTROYED (window) || surfaces == NULL)
+  if (GDK_WINDOW_DESTROYED (window) || textures == NULL)
     return;
 
   impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
@@ -2276,48 +2276,42 @@ gdk_win32_window_set_icon_list (GdkWindow *window,
   small_h = GetSystemMetrics (SM_CYSMICON);
 
   /* find closest sized icons in the list */
-  big_surface = NULL;
-  small_surface = NULL;
+  big_texture = NULL;
+  small_texture = NULL;
   big_diff = 0;
   small_diff = 0;
 
-  while (surfaces)
+  for (l = textures; l; l = l->next)
     {
-      surface = surfaces->data;
-      w = cairo_image_surface_get_width (surface);
-      h = cairo_image_surface_get_height (surface);
+      texture = l->data;
+      w = gdk_texture_get_width (texture);
+      h = gdk_texture_get_height (texture);
 
       dw = ABS (w - big_w);
       dh = ABS (h - big_h);
       diff = dw*dw + dh*dh;
-      if (big_surface == NULL || diff < big_diff)
+      if (big_texture == NULL || diff < big_diff)
         {
-          big_surface = surface;
+          big_texture = texture;
           big_diff = diff;
         }
 
       dw = ABS (w - small_w);
       dh = ABS (h - small_h);
       diff = dw*dw + dh*dh;
-      if (small_surface == NULL || diff < small_diff)
+      if (small_texture == NULL || diff < small_diff)
         {
-          small_surface = surface;
+          small_texture = texture;
           small_diff = diff;
         }
 
-      surfaces = surfaces->next;
+      textures = textures->next;
     }
 
   /* Create the icons */
-  big_pixbuf = gdk_pixbuf_get_from_surface (big_surface, 0, 0,
-                                            cairo_image_surface_get_width (big_surface),
-                                            cairo_image_surface_get_height (big_surface));
-  big_hicon = _gdk_win32_pixbuf_to_hicon (big_pixbuf);
+  big_hicon = gdk_win32_texture_to_hicon (big_texture);
   g_object_unref (big_pixbuf);
-  small_pixbuf = gdk_pixbuf_get_from_surface (small_surface, 0, 0,
-                                              cairo_image_surface_get_width (small_surface),
-                                              cairo_image_surface_get_height (small_surface));
-  small_hicon = _gdk_win32_pixbuf_to_hicon (small_pixbuf);
+  small_hicon = _gdk_win32_texture_to_hicon (small_texture);
   g_object_unref (small_pixbuf);
 
   /* Set the icons */
@@ -2337,7 +2331,7 @@ gdk_win32_window_set_icon_list (GdkWindow *window,
 
 static void
 gdk_win32_window_set_icon_name (GdkWindow   *window,
-                         const gchar *name)
+                                const gchar *name)
 {
   /* In case I manage to confuse this again (or somebody else does):
    * Please note that "icon name" here really *does* mean the name or
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index ddd08b1..cfd7273 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -38,6 +38,7 @@
 #include "gdkdisplay-x11.h"
 #include "gdkglcontext-x11.h"
 #include "gdkprivate-x11.h"
+#include "gdktextureprivate.h"
 #include "gdk-private.h"
 
 #include <stdlib.h>
@@ -3115,7 +3116,7 @@ gdk_window_update_icon (GdkWindow *window,
                         GList     *icon_list)
 {
   GdkToplevelX11 *toplevel;
-  cairo_surface_t *best_icon;
+  GdkTexture *best_icon;
   GList *tmp_list;
   int best_size;
 
@@ -3139,18 +3140,18 @@ gdk_window_update_icon (GdkWindow *window,
   best_icon = NULL;
   for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next)
     {
-      cairo_surface_t *surface = tmp_list->data;
+      GdkTexture *texture = tmp_list->data;
       int this;
 
       /* average width and height - if someone passes in a rectangular
        * icon they deserve what they get.
        */
-      this = cairo_image_surface_get_width (surface) + cairo_image_surface_get_height (surface);
+      this = gdk_texture_get_width (texture) + gdk_texture_get_height (texture);
       this /= 2;
 
       if (best_icon == NULL)
         {
-          best_icon = surface;
+          best_icon = texture;
           best_size = this;
         }
       else
@@ -3162,7 +3163,7 @@ gdk_window_update_icon (GdkWindow *window,
               (ABS (best_size - IDEAL_SIZE) <
                ABS (this - IDEAL_SIZE)))
             {
-              best_icon = surface;
+              best_icon = texture;
               best_size = this;
             }
         }
@@ -3170,18 +3171,21 @@ gdk_window_update_icon (GdkWindow *window,
 
   if (best_icon)
     {
-      int width = cairo_image_surface_get_width (best_icon);
-      int height = cairo_image_surface_get_height (best_icon);
+      int width = gdk_texture_get_width (best_icon);
+      int height = gdk_texture_get_height (best_icon);
+      cairo_surface_t *surface;
       cairo_t *cr;
 
       toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window,
                                                                     width,
                                                                     height);
 
+      surface = gdk_texture_download_surface (best_icon);
+
       cr = cairo_create (toplevel->icon_pixmap);
       cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-      cairo_set_source_surface (cr, best_icon, 0, 0);
-      if (cairo_surface_get_content (best_icon) == CAIRO_CONTENT_COLOR_ALPHA)
+      cairo_set_source_surface (cr, surface, 0, 0);
+      if (cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA)
         {
           /* Saturate the image, so it has bilevel alpha */
           cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
@@ -3193,18 +3197,20 @@ gdk_window_update_icon (GdkWindow *window,
       cairo_paint (cr);
       cairo_destroy (cr);
 
-      if (cairo_surface_get_content (best_icon) == CAIRO_CONTENT_COLOR_ALPHA)
+      if (cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA)
         {
           toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
                                                                        width,
                                                                        height);
 
           cr = cairo_create (toplevel->icon_mask);
-          cairo_set_source_surface (cr, best_icon, 0, 0);
+          cairo_set_source_surface (cr, surface, 0, 0);
           cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
           cairo_paint (cr);
           cairo_destroy (cr);
         }
+
+      cairo_surface_destroy (surface);
     }
 
   update_wm_hints (window, FALSE);
@@ -3212,19 +3218,16 @@ gdk_window_update_icon (GdkWindow *window,
 
 static void
 gdk_x11_window_set_icon_list (GdkWindow *window,
-                             GList     *surfaces)
+                             GList     *textures)
 {
   gulong *data;
-  guchar *pixels;
   gulong *p;
   gint size;
   GList *l;
-  cairo_surface_t *surface;
-  gint width, height, stride;
-  gint x, y;
+  gint width, height;
+  GdkTexture *texture;
   GdkDisplay *display;
   gint n;
-  cairo_format_t format;
 
   if (GDK_WINDOW_DESTROYED (window) ||
       !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window))
@@ -3234,16 +3237,12 @@ gdk_x11_window_set_icon_list (GdkWindow *window,
 
   size = 0;
   n = 0;
-  for (l = surfaces; l != NULL; l = l->next)
+  for (l = textures; l != NULL; l = l->next)
     {
-      surface = l->data;
+      texture = l->data;
 
-      width = cairo_image_surface_get_width (surface);
-      height = cairo_image_surface_get_height (surface);
-      format = cairo_image_surface_get_format (surface);
-
-      if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24)
-        continue;
+      width = gdk_texture_get_width (texture);
+      height = gdk_texture_get_height (texture);
 
       /* silently ignore overlarge icons */
       if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display))
@@ -3256,47 +3255,19 @@ gdk_x11_window_set_icon_list (GdkWindow *window,
   data = g_malloc (size * sizeof (gulong));
 
   p = data;
-  for (l = surfaces; l != NULL && n > 0; l = l->next)
+  for (l = textures; l != NULL && n > 0; l = l->next)
     {
-      surface = l->data;
-
-      width = cairo_image_surface_get_width (surface);
-      height = cairo_image_surface_get_height (surface);
-      stride = cairo_image_surface_get_stride (surface);
-      format = cairo_image_surface_get_format (surface);
+      texture = l->data;
 
-      if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24)
-        continue;
+      width = gdk_texture_get_width (texture);
+      height = gdk_texture_get_height (texture);
 
       *p++ = width;
       *p++ = height;
 
-      pixels = cairo_image_surface_get_data (surface);
-
-      for (y = 0; y < height; y++)
-       {
-         for (x = 0; x < width; x++)
-           {
-             guchar r, g, b, a;
-              a = 255;
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-              if (format == CAIRO_FORMAT_ARGB32)
-                a = pixels[y*stride + x*4 + 3];
-              r = pixels[y*stride + x*4 + 2];
-              g = pixels[y*stride + x*4 + 1];
-              b = pixels[y*stride + x*4 + 0];
-#else
-              if (format == CAIRO_FORMAT_ARGB32)
-                a = pixels[y*stride + x*4 + 0];
-              r = pixels[y*stride + x*4 + 1];
-              g = pixels[y*stride + x*4 + 2];
-              b = pixels[y*stride + x*4 + 3];
-#endif
-
-             *p++ = a << 24 | r << 16 | g << 8 | b ;
-           }
-       }
+      gdk_texture_download (texture, (guchar *) p, width * 4);
 
+      p += width * height;
       n--;
     }
 
@@ -3318,7 +3289,7 @@ gdk_x11_window_set_icon_list (GdkWindow *window,
   
   g_free (data);
 
-  gdk_window_update_icon (window, surfaces);
+  gdk_window_update_icon (window, textures);
 }
 
 static gboolean
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index d6ef590..f1240eb 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -200,7 +200,7 @@ _gtk_header_bar_update_window_icon (GtkHeaderBar *bar,
                                     GtkWindow    *window)
 {
   GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
-  cairo_surface_t *surface;
+  GdkTexture *texture;
   gint scale;
 
   if (priv->titlebar_icon == NULL)
@@ -208,14 +208,14 @@ _gtk_header_bar_update_window_icon (GtkHeaderBar *bar,
 
   scale = gtk_widget_get_scale_factor (priv->titlebar_icon);
   if (GTK_IS_BUTTON (gtk_widget_get_parent (priv->titlebar_icon)))
-    surface = gtk_window_get_icon_for_size (window, 16, scale);
+    texture = gtk_window_get_icon_for_size (window, 16 * scale);
   else
-    surface = gtk_window_get_icon_for_size (window, 20, scale);
+    texture = gtk_window_get_icon_for_size (window, 20 * scale);
 
-  if (surface)
+  if (texture)
     {
-      gtk_image_set_from_surface (GTK_IMAGE (priv->titlebar_icon), surface);
-      cairo_surface_destroy (surface);
+      gtk_image_set_from_texture (GTK_IMAGE (priv->titlebar_icon), texture);
+      g_object_unref (texture);
       gtk_widget_show (priv->titlebar_icon);
 
       return TRUE;
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 775b6c4..ed60d5c 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -923,11 +923,11 @@ gtk_window_class_init (GtkWindowClass *klass)
                             GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
   window_props[PROP_ICON] =
-      g_param_spec_boxed ("icon",
-                          P_("Icon"),
-                          P_("Icon for this window"),
-                         CAIRO_GOBJECT_TYPE_SURFACE,
-                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+      g_param_spec_object ("icon",
+                           P_("Icon"),
+                           P_("Icon for this window"),
+                          GDK_TYPE_TEXTURE,
+                           GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
   /**
    * GtkWindow:mnemonics-visible:
@@ -2007,7 +2007,7 @@ gtk_window_set_property (GObject      *object,
       break;
     case PROP_ICON:
       gtk_window_set_icon (window,
-                           g_value_get_boxed (value));
+                           g_value_get_object (value));
       break;
     case PROP_ICON_NAME:
       gtk_window_set_icon_name (window, g_value_get_string (value));
@@ -2117,7 +2117,7 @@ gtk_window_get_property (GObject      *object,
       g_value_set_boolean (value, priv->destroy_with_parent);
       break;
     case PROP_ICON:
-      g_value_set_boxed (value, gtk_window_get_icon (window));
+      g_value_set_object (value, gtk_window_get_icon (window));
       break;
     case PROP_ICON_NAME:
       g_value_set_string (value, gtk_window_get_icon_name (window));
@@ -4413,9 +4413,9 @@ icon_list_from_theme (GtkWindow   *window,
 {
   GtkWindowPrivate *priv = window->priv;
   GList *list;
-
   GtkIconTheme *icon_theme;
-  cairo_surface_t *icon;
+  GdkTexture *icon;
+  GdkPixbuf *pixbuf;
   gint *sizes;
   gint i;
 
@@ -4434,17 +4434,19 @@ icon_list_from_theme (GtkWindow   *window,
        * fixed size of 48.
        */ 
       if (sizes[i] == -1)
-       icon = gtk_icon_theme_load_surface (icon_theme, name,
-                                           48, priv->scale,
-                                           _gtk_widget_get_window (GTK_WIDGET (window)),
-                                           0, NULL);
+        pixbuf = gtk_icon_theme_load_icon_for_scale (icon_theme, name,
+                                                    48, priv->scale,
+                                                    0, NULL);
       else
-       icon = gtk_icon_theme_load_surface (icon_theme, name,
-                                           sizes[i], priv->scale,
-                                           _gtk_widget_get_window (GTK_WIDGET (window)),
-                                           0, NULL);
-      if (icon)
-       list = g_list_append (list, icon);
+        pixbuf = gtk_icon_theme_load_icon_for_scale (icon_theme, name,
+                                                    sizes[i], priv->scale,
+                                                    0, NULL);
+      if (pixbuf)
+        {
+          icon = gdk_texture_new_for_pixbuf (pixbuf);
+         list = g_list_append (list, icon);
+          g_object_unref (pixbuf);
+        }
     }
 
   g_free (sizes);
@@ -4523,94 +4525,79 @@ gtk_window_realize_icon (GtkWindow *window)
 
   if (info->using_themed_icon) 
     {
-      g_list_free_full (icon_list, (GDestroyNotify)cairo_surface_destroy);
+      g_list_free_full (icon_list, g_object_unref);
     }
 }
 
-static cairo_surface_t *
-icon_from_list (GtkWindow *window,
-               GList *list,
-                gint   size,
-               gint   scale)
+static GdkTexture *
+icon_from_list (GList *list,
+                gint   size)
 {
-  cairo_surface_t *best;
-  cairo_surface_t *surface;
+  GdkTexture *texture;
+  cairo_surface_t *source, *target;
+  cairo_t *cr;
   GList *l;
 
-  best = NULL;
-  /* Look for exact match */
+  /* Look for possible match */
   for (l = list; l; l = l->next)
     {
-      surface = list->data;
-      double x_scale;
-
-      cairo_surface_get_device_scale (surface, &x_scale, NULL);
+      texture = list->data;
       
-      if (cairo_image_surface_get_width (surface) == size &&
-         x_scale == scale)
-       {
-          best = cairo_surface_reference (surface);
-          break;
-       }
-    }
-
-  if (best != NULL)
-    return best;
-    
-  /* Ignore scale */
-  for (l = list; l; l = l->next)
-    {
-      surface = list->data;
-      double x_scale;
-
-      cairo_surface_get_device_scale (surface, &x_scale, NULL);
-      
-      if (cairo_image_surface_get_width (surface) * x_scale <= size)
-       {
-         best = cairo_surface_reference (surface);
-         break;
-       }
-    }
-
-  if (best == NULL && list != NULL)
-    best = cairo_surface_reference ((cairo_surface_t *)list->data);
-
+      if (gdk_texture_get_width (texture) <= size)
+        return g_object_ref (texture);
+    }
+
+  /* scale larger match down */
+  texture = list->data;
+  source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                       gdk_texture_get_width (texture),
+                                       gdk_texture_get_height (texture));
+  gdk_texture_download (texture,
+                        cairo_image_surface_get_data (source),
+                        cairo_image_surface_get_stride (source));
+  cairo_surface_mark_dirty (source);
+
+  target = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
+  cr = cairo_create (target);
+  cairo_set_source_surface (cr, source , 0, 0);
+  cairo_scale (cr,
+              size / gdk_texture_get_width (texture),
+              size / gdk_texture_get_height (texture));
+  cairo_paint (cr);
+  cairo_destroy (cr);
+  cairo_surface_destroy (source);
+
+  texture = gdk_texture_new_for_data (cairo_image_surface_get_data (target),
+                                      cairo_image_surface_get_width (target),
+                                      cairo_image_surface_get_height (target),
+                                      cairo_image_surface_get_stride (target));
+  cairo_surface_destroy (target);
+
+  return texture;
+}
+
+static GdkTexture *
+icon_from_name (const gchar *name,
+                gint         size)
+{
+  GdkPixbuf *pixbuf;
+  GdkTexture *texture;
   
-  if (best)
-    {
-      cairo_t *cr;
-      surface =
-       gdk_window_create_similar_image_surface (_gtk_widget_get_window (GTK_WIDGET(window)),
-                                                CAIRO_FORMAT_ARGB32,
-                                                size * scale, size * scale, scale);
-      cr = cairo_create (surface);
-      cairo_set_source_surface (cr, best, 0, 0);
-      cairo_scale (cr,
-                  size / cairo_image_surface_get_width (best),
-                  size / cairo_image_surface_get_height (best));
-      cairo_paint (cr);
-      cairo_destroy (cr);
-    }
+  pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+                                    name, size,
+                                    GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
+  if (pixbuf == NULL)
+    return NULL;
 
-  return best;
-}
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  g_object_unref (pixbuf);
 
-static cairo_surface_t *
-icon_from_name (GtkWindow *window,
-               const gchar *name,
-                gint         size,
-               gint         scale)
-{
-  return gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
-                                     name, size, scale,
-                                     _gtk_widget_get_window (GTK_WIDGET(window)),
-                                     GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
+  return texture;
 }
 
-cairo_surface_t *
+GdkTexture *
 gtk_window_get_icon_for_size (GtkWindow *window,
-                              int        size,
-                             int        scale)
+                              int        size)
 {
   GtkWindowPrivate *priv = window->priv;
   GtkWindowIconInfo *info;
@@ -4619,24 +4606,24 @@ gtk_window_get_icon_for_size (GtkWindow *window,
   info = ensure_icon_info (window);
 
   if (info->icon_list != NULL)
-    return icon_from_list (window, info->icon_list, size, scale);
+    return icon_from_list (info->icon_list, size);
 
   name = gtk_window_get_icon_name (window);
   if (name != NULL)
-    return icon_from_name (window, name, size, scale);
+    return icon_from_name (name, size);
 
   if (priv->transient_parent != NULL)
     {
       info = ensure_icon_info (priv->transient_parent);
       if (info->icon_list)
-        return icon_from_list (window, info->icon_list, size, scale);
+        return icon_from_list (info->icon_list, size);
     }
 
   if (default_icon_list != NULL)
-    return icon_from_list (window, default_icon_list, size, scale);
+    return icon_from_list (default_icon_list, size);
 
   if (default_icon_name != NULL)
-    return icon_from_name (window, default_icon_name, size, scale);
+    return icon_from_name (default_icon_name, size);
 
   return NULL;
 }
@@ -4662,7 +4649,7 @@ gtk_window_unrealize_icon (GtkWindow *window)
 /**
  * gtk_window_set_icon_list:
  * @window: a #GtkWindow
- * @list: (element-type cairo_surface_t): list of image surfaces
+ * @list: (element-type GdkTexture): list of image surfaces
  *
  * Sets up the icon representing a #GtkWindow. The icon is used when
  * the window is minimized (also known as iconified).  Some window
@@ -4704,9 +4691,9 @@ gtk_window_set_icon_list (GtkWindow  *window,
     return;
 
   g_list_foreach (list,
-                  (GFunc) cairo_surface_reference, NULL);
+                  (GFunc) g_object_ref, NULL);
 
-  g_list_free_full (info->icon_list, (GDestroyNotify)cairo_surface_destroy);
+  g_list_free_full (info->icon_list, g_object_unref);
 
   info->icon_list = g_list_copy (list);
 
@@ -4731,7 +4718,7 @@ gtk_window_set_icon_list (GtkWindow  *window,
  * The list is copied, but the reference count on each
  * member won’t be incremented.
  *
- * Returns: (element-type cairo_surface_t) (transfer container): copy of window’s icon list
+ * Returns: (element-type GdkTexture) (transfer container): copy of window’s icon list
  **/
 GList*
 gtk_window_get_icon_list (GtkWindow  *window)
@@ -4775,12 +4762,12 @@ gtk_window_get_icon_list (GtkWindow  *window)
  **/
 void
 gtk_window_set_icon (GtkWindow  *window,
-                     cairo_surface_t *icon)
+                     GdkTexture *icon)
 {
   GList *list;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
-  g_return_if_fail (icon == NULL || cairo_surface_get_type (icon) == CAIRO_SURFACE_TYPE_IMAGE);
+  g_return_if_fail (icon == NULL || GDK_IS_TEXTURE (icon));
 
   list = NULL;
 
@@ -4875,9 +4862,9 @@ gtk_window_get_icon_name (GtkWindow *window)
  * called gtk_window_set_icon_list(), gets the first icon in
  * the icon list).
  *
- * Returns: (transfer none): icon for window
+ * Returns: (transfer none) (nullable: icon for window or %NULL if none
  **/
-cairo_surface_t *
+GdkTexture *
 gtk_window_get_icon (GtkWindow  *window)
 {
   GtkWindowIconInfo *info;
@@ -4886,21 +4873,20 @@ gtk_window_get_icon (GtkWindow  *window)
 
   info = get_icon_info (window);
   if (info && info->icon_list)
-    return (cairo_surface_t *) (info->icon_list->data);
+    return (GdkTexture *) (info->icon_list->data);
   else
     return NULL;
 }
 
 /* Load surface, printing warning on failure if error == NULL
  */
-static cairo_surface_t *
-load_surface_verbosely (GdkWindow *window,
-                       const char *filename,
+static GdkTexture *
+load_texture_verbosely (const char *filename,
                        GError    **err)
 {
   GError *local_err = NULL;
+  GdkTexture *texture;
   GdkPixbuf *pixbuf;
-  cairo_surface_t *surface = NULL;
 
   pixbuf = gdk_pixbuf_new_from_file (filename, &local_err);
 
@@ -4914,14 +4900,13 @@ load_surface_verbosely (GdkWindow *window,
                     filename, local_err->message);
          g_error_free (local_err);
        }
-    }
-  else
-    {
-      surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, window);
-      g_object_unref (pixbuf);
+      return NULL;
     }
 
-  return surface;
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  g_object_unref (pixbuf);
+
+  return texture;
 }
 
 /**
@@ -4945,12 +4930,12 @@ gtk_window_set_icon_from_file (GtkWindow   *window,
                               const gchar *filename,
                               GError     **err)
 {
-  cairo_surface_t *surface = load_surface_verbosely (_gtk_widget_get_window (GTK_WIDGET (window)), filename, 
err);
+  GdkTexture *texture = load_texture_verbosely (filename, err);
 
-  if (surface)
+  if (texture)
     {
-      gtk_window_set_icon (window, surface);
-      cairo_surface_destroy (surface);
+      gtk_window_set_icon (window, texture);
+      g_object_unref (texture);
       
       return TRUE;
     }
@@ -4960,7 +4945,7 @@ gtk_window_set_icon_from_file (GtkWindow   *window,
 
 /**
  * gtk_window_set_default_icon_list:
- * @list: (element-type cairo_surface_t) (transfer container): a list of #cairo_surface_t image surfaces
+ * @list: (element-type GdkTexture) (transfer container): a list of #GdkTextures
  *
  * Sets an icon list to be used as fallback for windows that haven't
  * had gtk_window_set_icon_list() called on them to set up a
@@ -4983,9 +4968,9 @@ gtk_window_set_default_icon_list (GList *list)
   default_icon_serial++;
   
   g_list_foreach (list,
-                  (GFunc) cairo_surface_reference, NULL);
+                  (GFunc) g_object_ref, NULL);
 
-  g_list_free_full (default_icon_list, (GDestroyNotify)cairo_surface_destroy);
+  g_list_free_full (default_icon_list, g_object_unref);
 
   default_icon_list = g_list_copy (list);
   
@@ -5020,11 +5005,11 @@ gtk_window_set_default_icon_list (GList *list)
  * Since: 2.4
  **/
 void
-gtk_window_set_default_icon (cairo_surface_t *icon)
+gtk_window_set_default_icon (GdkTexture *icon)
 {
   GList *list;
   
-  g_return_if_fail (cairo_surface_get_type (icon) == CAIRO_SURFACE_TYPE_IMAGE);
+  g_return_if_fail (GDK_IS_TEXTURE (icon));
 
   list = g_list_prepend (NULL, icon);
   gtk_window_set_default_icon_list (list);
@@ -5114,12 +5099,12 @@ gboolean
 gtk_window_set_default_icon_from_file (const gchar *filename,
                                       GError     **err)
 {
-  cairo_surface_t *surface = load_surface_verbosely (NULL, filename, err);
+  GdkTexture *texture = load_texture_verbosely (filename, err);
 
-  if (surface)
+  if (texture)
     {
-      gtk_window_set_default_icon (surface);
-      cairo_surface_destroy (surface);
+      gtk_window_set_default_icon (texture);
+      g_object_unref (texture);
       
       return TRUE;
     }
@@ -5135,7 +5120,7 @@ gtk_window_set_default_icon_from_file (const gchar *filename,
  * but the surfaces in the list have not had their reference count
  * incremented.
  * 
- * Returns: (element-type cairo_surface_t) (transfer container): copy of default icon list 
+ * Returns: (element-type GdkTexture) (transfer container): copy of default icon list 
  **/
 GList*
 gtk_window_get_default_icon_list (void)
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 7cf59df..19d07f5 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -275,7 +275,7 @@ GDK_AVAILABLE_IN_ALL
 GList*     gtk_window_get_icon_list                (GtkWindow  *window);
 GDK_AVAILABLE_IN_ALL
 void       gtk_window_set_icon                     (GtkWindow  *window,
-                                                    cairo_surface_t  *icon);
+                                                    GdkTexture *texture);
 GDK_AVAILABLE_IN_ALL
 void       gtk_window_set_icon_name                (GtkWindow   *window,
                                                    const gchar *name);
@@ -284,7 +284,7 @@ gboolean   gtk_window_set_icon_from_file           (GtkWindow   *window,
                                                    const gchar *filename,
                                                    GError     **err);
 GDK_AVAILABLE_IN_ALL
-cairo_surface_t * gtk_window_get_icon              (GtkWindow  *window);
+GdkTexture *  gtk_window_get_icon                  (GtkWindow  *window);
 GDK_AVAILABLE_IN_ALL
 const gchar * gtk_window_get_icon_name             (GtkWindow  *window);
 GDK_AVAILABLE_IN_ALL
@@ -292,7 +292,7 @@ void       gtk_window_set_default_icon_list        (GList      *list);
 GDK_AVAILABLE_IN_ALL
 GList*     gtk_window_get_default_icon_list        (void);
 GDK_AVAILABLE_IN_ALL
-void       gtk_window_set_default_icon             (cairo_surface_t  *icon);
+void       gtk_window_set_default_icon             (GdkTexture  *icon);
 GDK_AVAILABLE_IN_ALL
 void       gtk_window_set_default_icon_name        (const gchar *name);
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index 7582042..d82d876 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -110,9 +110,8 @@ GtkWidget * _gtk_window_get_popover_parent (GtkWindow *window,
 gboolean    _gtk_window_is_popover_widget  (GtkWindow *window,
                                             GtkWidget *popover);
 
-cairo_surface_t *gtk_window_get_icon_for_size (GtkWindow *window,
-                                              int        size,
-                                              int        scale);
+GdkTexture *     gtk_window_get_icon_for_size (GtkWindow *window,
+                                              int        size);
 
 void       gtk_window_set_use_subsurface (GtkWindow *window,
                                           gboolean   use_subsurface);


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