[gtk+] Use a texture instead of a pixbuf in gtk_render_icon



commit b65f87192973c6a13633af5700b893fc7594e695
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Nov 29 23:30:47 2017 -0500

    Use a texture instead of a pixbuf in gtk_render_icon
    
    This gets rid of more GdkPixbuf in the API.
    
    Update all callers.

 demos/gtk-demo/foreigndrawing.c |   10 +++++++---
 gtk/gtkrender.c                 |   11 ++++++-----
 gtk/gtkrender.h                 |    4 ++--
 3 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/demos/gtk-demo/foreigndrawing.c b/demos/gtk-demo/foreigndrawing.c
index 9a963f1..842696e 100644
--- a/demos/gtk-demo/foreigndrawing.c
+++ b/demos/gtk-demo/foreigndrawing.c
@@ -830,6 +830,7 @@ draw_spinbutton (GtkWidget *widget,
   GtkIconTheme *icon_theme;
   GtkIconInfo *icon_info;
   GdkPixbuf *pixbuf;
+  GdkTexture *texture;
   gint icon_width, icon_height, icon_size;
   gint button_width;
   gint contents_x, contents_y, contents_width, contents_height;
@@ -857,23 +858,26 @@ draw_spinbutton (GtkWidget *widget,
   icon_size = MIN (icon_width, icon_height);
   icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-add-symbolic", icon_size, 0);
   pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, up_context, NULL, NULL);
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
   g_object_unref (icon_info);
   draw_style_common (up_context, cr, x + width - button_width, y, button_width, *height,
                      &contents_x, &contents_y, &contents_width, &contents_height);
-  gtk_render_icon (up_context, cr, pixbuf, contents_x, contents_y + (contents_height - icon_size) / 2);
+  gtk_render_icon (up_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2);
   g_object_unref (pixbuf);
-
+  g_object_unref (texture);
 
   gtk_style_context_get (down_context,
                          "min-width", &icon_width, "min-height", &icon_height, NULL);
   icon_size = MIN (icon_width, icon_height);
   icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-remove-symbolic", icon_size, 0);
   pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, down_context, NULL, NULL);
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
   g_object_unref (icon_info);
   draw_style_common (down_context, cr, x + width - 2 * button_width, y, button_width, *height,
                      &contents_x, &contents_y, &contents_width, &contents_height);
-  gtk_render_icon (down_context, cr, pixbuf, contents_x, contents_y + (contents_height - icon_size) / 2);
+  gtk_render_icon (down_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2);
   g_object_unref (pixbuf);
+  g_object_unref (texture);
 
   g_object_unref (down_context);
   g_object_unref (up_context);
diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c
index 39ffdf3..e898999 100644
--- a/gtk/gtkrender.c
+++ b/gtk/gtkrender.c
@@ -35,6 +35,7 @@
 #include "gtkstylecontextprivate.h"
 
 #include "gsk/gskroundedrectprivate.h"
+#include <gdk/gdktextureprivate.h>
 
 #include "fallback-c89.c"
 
@@ -852,13 +853,13 @@ gtk_render_activity (GtkStyleContext *context,
  * gtk_render_icon:
  * @context: a #GtkStyleContext
  * @cr: a #cairo_t
- * @pixbuf: a #GdkPixbuf containing the icon to draw
+ * @texture: a #GdkTexture containing the icon to draw
  * @x: X position for the @pixbuf
  * @y: Y position for the @pixbuf
  *
- * Renders the icon in @pixbuf at the specified @x and @y coordinates.
+ * Renders the icon in @texture at the specified @x and @y coordinates.
  *
- * This function will render the icon in @pixbuf at exactly its size,
+ * This function will render the icon in @texture at exactly its size,
  * regardless of scaling factors, which may not be appropriate when
  * drawing on displays with high pixel densities.
  *
@@ -870,7 +871,7 @@ gtk_render_activity (GtkStyleContext *context,
 void
 gtk_render_icon (GtkStyleContext *context,
                  cairo_t         *cr,
-                 GdkPixbuf       *pixbuf,
+                 GdkTexture      *texture,
                  gdouble          x,
                  gdouble          y)
 {
@@ -879,7 +880,7 @@ gtk_render_icon (GtkStyleContext *context,
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (cr != NULL);
 
-  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
+  surface = gdk_texture_download_surface (texture);
 
   gtk_css_style_render_icon_surface (gtk_style_context_lookup_style (context),
                                      cr,
diff --git a/gtk/gtkrender.h b/gtk/gtkrender.h
index 46c0304..21caea9 100644
--- a/gtk/gtkrender.h
+++ b/gtk/gtkrender.h
@@ -134,10 +134,10 @@ void        gtk_render_activity    (GtkStyleContext     *context,
                                     gdouble              y,
                                     gdouble              width,
                                     gdouble              height);
-GDK_AVAILABLE_IN_3_2
+GDK_AVAILABLE_IN_3_94
 void        gtk_render_icon        (GtkStyleContext     *context,
                                     cairo_t             *cr,
-                                    GdkPixbuf           *pixbuf,
+                                    GdkTexture          *texture,
                                     gdouble              x,
                                     gdouble              y);
 GDK_AVAILABLE_IN_3_10


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