[gtksourceview/wip/chergert/gsv-gtk4: 91/131] completion: port from GdkPixbuf to GdkTexture



commit 08f7bf601543d577da68b534ce7d4c080469f519
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 15 14:05:49 2020 -0800

    completion: port from GdkPixbuf to GdkTexture
    
    We want to use GdkTexture instead of GdkPixbuf so that the widget snapshot
    code can cache nodes and/or textures on the GPU.

 gtksourceview/gtksourcecompletion.c         | 16 +++++++++-------
 gtksourceview/gtksourcecompletionitem.c     | 14 +++++++-------
 gtksourceview/gtksourcecompletionitem.h     |  2 +-
 gtksourceview/gtksourcecompletionmodel.c    |  6 +++---
 gtksourceview/gtksourcecompletionproposal.c | 10 +++++-----
 gtksourceview/gtksourcecompletionproposal.h |  7 +++----
 gtksourceview/gtksourcecompletionprovider.c |  8 ++++----
 gtksourceview/gtksourcecompletionprovider.h |  4 ++--
 8 files changed, 34 insertions(+), 33 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 3df3c6ea..77dbb503 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -842,12 +842,14 @@ update_selection_label (GtkSourceCompletion *completion)
        }
        else
        {
+               GdkTexture *texture;
+
                gchar *temp_name = gtk_source_completion_provider_get_name (visible);
                name = g_markup_escape_text (temp_name, -1);
                g_free (temp_name);
 
-               gtk_image_set_from_pixbuf (completion->selection_image,
-                                          gtk_source_completion_provider_get_icon (visible));
+               texture = gtk_source_completion_provider_get_icon (visible);
+               gtk_image_set_from_paintable (completion->selection_image, GDK_PAINTABLE (texture));
        }
 
        selection_text = g_strdup_printf ("<small>%s (%d/%d)</small>", name, pos + 1, num + 1);
@@ -1988,21 +1990,21 @@ cell_icon_func (GtkTreeViewColumn *column,
                 GtkTreeIter       *iter,
                 gpointer           data)
 {
-       GdkPixbuf *pixbuf;
+       GdkTexture *texture;
        gchar *icon_name;
        GIcon *gicon;
        gboolean set = FALSE;
 
        gtk_tree_model_get (model, iter,
-                           GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON, &pixbuf,
+                           GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON, &texture,
                            GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON_NAME, &icon_name,
                            GTK_SOURCE_COMPLETION_MODEL_COLUMN_GICON, &gicon,
                            -1);
 
-       if (pixbuf != NULL)
+       if (texture != NULL)
        {
-               g_object_set (cell, "pixbuf", pixbuf, NULL);
-               g_object_unref (pixbuf);
+               g_object_set (cell, "texture", texture, NULL);
+               g_object_unref (texture);
                set = TRUE;
        }
 
diff --git a/gtksourceview/gtksourcecompletionitem.c b/gtksourceview/gtksourcecompletionitem.c
index 23ec2632..a28821de 100644
--- a/gtksourceview/gtksourcecompletionitem.c
+++ b/gtksourceview/gtksourcecompletionitem.c
@@ -38,7 +38,7 @@ typedef struct
        gchar *label;
        gchar *markup;
        gchar *text;
-       GdkPixbuf *icon;
+       GdkTexture *icon;
        gchar *icon_name;
        GIcon *gicon;
        gchar *info;
@@ -92,7 +92,7 @@ gtk_source_completion_proposal_get_text_impl (GtkSourceCompletionProposal *propo
        return g_strdup (priv->text);
 }
 
-static GdkPixbuf *
+static GdkTexture *
 gtk_source_completion_proposal_get_icon_impl (GtkSourceCompletionProposal *proposal)
 {
        GtkSourceCompletionItem *item = GTK_SOURCE_COMPLETION_ITEM (proposal);
@@ -321,14 +321,14 @@ gtk_source_completion_item_class_init (GtkSourceCompletionItemClass *klass)
        /**
         * GtkSourceCompletionItem:icon:
         *
-        * The #GdkPixbuf for the icon to be shown for this proposal.
+        * The #GdkTexture for the icon to be shown for this proposal.
         */
        g_object_class_install_property (object_class,
                                         PROP_ICON,
                                         g_param_spec_object ("icon",
                                                              "Icon",
                                                              "",
-                                                             GDK_TYPE_PIXBUF,
+                                                             GDK_TYPE_TEXTURE,
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_STATIC_STRINGS));
 
@@ -477,18 +477,18 @@ gtk_source_completion_item_set_text (GtkSourceCompletionItem *item,
 /**
  * gtk_source_completion_item_set_icon:
  * @item: a #GtkSourceCompletionItem.
- * @icon: (nullable): the #GdkPixbuf, or %NULL.
+ * @icon: (nullable): the #GdkTexture, or %NULL.
  *
  * Since: 3.24
  */
 void
 gtk_source_completion_item_set_icon (GtkSourceCompletionItem *item,
-                                     GdkPixbuf               *icon)
+                                     GdkTexture              *icon)
 {
        GtkSourceCompletionItemPrivate *priv = gtk_source_completion_item_get_instance_private (item);
 
        g_return_if_fail (GTK_SOURCE_IS_COMPLETION_ITEM (item));
-       g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
+       g_return_if_fail (icon == NULL || GDK_IS_TEXTURE (icon));
 
        if (g_set_object (&priv->icon, icon))
        {
diff --git a/gtksourceview/gtksourcecompletionitem.h b/gtksourceview/gtksourcecompletionitem.h
index 1666741b..1792c1d4 100644
--- a/gtksourceview/gtksourcecompletionitem.h
+++ b/gtksourceview/gtksourcecompletionitem.h
@@ -57,7 +57,7 @@ void                     gtk_source_completion_item_set_text      (GtkSourceComp
                                                                    const gchar             *text);
 GTK_SOURCE_AVAILABLE_IN_3_24
 void                     gtk_source_completion_item_set_icon      (GtkSourceCompletionItem *item,
-                                                                   GdkPixbuf               *icon);
+                                                                   GdkTexture              *icon);
 GTK_SOURCE_AVAILABLE_IN_3_24
 void                     gtk_source_completion_item_set_icon_name (GtkSourceCompletionItem *item,
                                                                    const gchar             *icon_name);
diff --git a/gtksourceview/gtksourcecompletionmodel.c b/gtksourceview/gtksourcecompletionmodel.c
index 97d46705..8bc3e8e9 100644
--- a/gtksourceview/gtksourcecompletionmodel.c
+++ b/gtksourceview/gtksourcecompletionmodel.c
@@ -513,12 +513,12 @@ tree_model_get_value (GtkTreeModel *tree_model,
                case GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON:
                        if (is_header (proposal_info))
                        {
-                               GdkPixbuf *icon = gtk_source_completion_provider_get_icon 
(completion_provider);
+                               GdkTexture *icon = gtk_source_completion_provider_get_icon 
(completion_provider);
                                g_value_set_object (value, (gpointer)icon);
                        }
                        else
                        {
-                               GdkPixbuf *icon = gtk_source_completion_proposal_get_icon 
(completion_proposal);
+                               GdkTexture *icon = gtk_source_completion_proposal_get_icon 
(completion_proposal);
                                g_value_set_object (value, (gpointer)icon);
                        }
                        break;
@@ -750,7 +750,7 @@ static void
 gtk_source_completion_model_init (GtkSourceCompletionModel *self)
 {
        self->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_MARKUP] = G_TYPE_STRING;
-       self->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON] = GDK_TYPE_PIXBUF;
+       self->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON] = GDK_TYPE_TEXTURE;
        self->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_ICON_NAME] = G_TYPE_STRING;
        self->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_GICON] = G_TYPE_ICON;
        self->column_types[GTK_SOURCE_COMPLETION_MODEL_COLUMN_PROPOSAL] = G_TYPE_OBJECT;
diff --git a/gtksourceview/gtksourcecompletionproposal.c b/gtksourceview/gtksourcecompletionproposal.c
index 8813b0df..68d40b21 100644
--- a/gtksourceview/gtksourcecompletionproposal.c
+++ b/gtksourceview/gtksourcecompletionproposal.c
@@ -37,7 +37,7 @@
  * The label may be specified using plain text or markup by implementing
  * the corresponding get function. Only one of those get functions
  * should return a value different from %NULL.
- * The icon may be specified as a #GdkPixbuf, as an icon name or as a #GIcon by
+ * The icon may be specified as a #GdkTexture, as an icon name or as a #GIcon by
  * implementing the corresponding get function. At most one of those get functions
  * should return a value different from %NULL, if they all return %NULL no icon
  * will be used.
@@ -71,7 +71,7 @@ gtk_source_completion_proposal_get_text_default (GtkSourceCompletionProposal *pr
        return NULL;
 }
 
-static GdkPixbuf *
+static GdkTexture *
 gtk_source_completion_proposal_get_icon_default (GtkSourceCompletionProposal *proposal)
 {
        return NULL;
@@ -212,11 +212,11 @@ gtk_source_completion_proposal_get_text (GtkSourceCompletionProposal *proposal)
  * gtk_source_completion_proposal_get_icon:
  * @proposal: a #GtkSourceCompletionProposal.
  *
- * Gets the #GdkPixbuf for the icon of @proposal.
+ * Gets the #GdkTexture for the icon of @proposal.
  *
- * Returns: (nullable) (transfer none): A #GdkPixbuf with the icon of @proposal.
+ * Returns: (nullable) (transfer none): A #GdkTexture with the icon of @proposal.
  */
-GdkPixbuf *
+GdkTexture *
 gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROPOSAL (proposal), NULL);
diff --git a/gtksourceview/gtksourcecompletionproposal.h b/gtksourceview/gtksourcecompletionproposal.h
index cf9c640b..7be25992 100644
--- a/gtksourceview/gtksourcecompletionproposal.h
+++ b/gtksourceview/gtksourcecompletionproposal.h
@@ -25,8 +25,7 @@
 #error "Only <gtksourceview/gtksource.h> can be included directly."
 #endif
 
-#include <glib-object.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
 
 #include "gtksourcetypes.h"
 
@@ -70,7 +69,7 @@ struct _GtkSourceCompletionProposalInterface
        gchar           *(*get_label)     (GtkSourceCompletionProposal *proposal);
        gchar           *(*get_markup)    (GtkSourceCompletionProposal *proposal);
        gchar           *(*get_text)      (GtkSourceCompletionProposal *proposal);
-       GdkPixbuf       *(*get_icon)      (GtkSourceCompletionProposal *proposal);
+       GdkTexture      *(*get_icon)      (GtkSourceCompletionProposal *proposal);
        const gchar     *(*get_icon_name) (GtkSourceCompletionProposal *proposal);
        GIcon           *(*get_gicon)     (GtkSourceCompletionProposal *proposal);
        gchar           *(*get_info)      (GtkSourceCompletionProposal *proposal);
@@ -89,7 +88,7 @@ gchar       *gtk_source_completion_proposal_get_markup    (GtkSourceCompletionPr
 GTK_SOURCE_AVAILABLE_IN_ALL
 gchar       *gtk_source_completion_proposal_get_text      (GtkSourceCompletionProposal *proposal);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GdkPixbuf   *gtk_source_completion_proposal_get_icon      (GtkSourceCompletionProposal *proposal);
+GdkTexture  *gtk_source_completion_proposal_get_icon      (GtkSourceCompletionProposal *proposal);
 GTK_SOURCE_AVAILABLE_IN_3_18
 const gchar *gtk_source_completion_proposal_get_icon_name (GtkSourceCompletionProposal *proposal);
 GTK_SOURCE_AVAILABLE_IN_3_18
diff --git a/gtksourceview/gtksourcecompletionprovider.c b/gtksourceview/gtksourcecompletionprovider.c
index 31b26c6a..c0f736d7 100644
--- a/gtksourceview/gtksourcecompletionprovider.c
+++ b/gtksourceview/gtksourcecompletionprovider.c
@@ -34,7 +34,7 @@
  *
  * The provider may be displayed in the completion window as a header row, showing
  * its name and optionally an icon.
- * The icon may be specified as a #GdkPixbuf, as an icon name or as a #GIcon by
+ * The icon may be specified as a #GdkTexture, as an icon name or as a #GIcon by
  * implementing the corresponding get function. At most one of those get functions
  * should return a value different from %NULL, if they all return %NULL no icon
  * will be used.
@@ -49,7 +49,7 @@ gtk_source_completion_provider_get_name_default (GtkSourceCompletionProvider *pr
        g_return_val_if_reached (NULL);
 }
 
-static GdkPixbuf *
+static GdkTexture *
 gtk_source_completion_provider_get_icon_default (GtkSourceCompletionProvider *provider)
 {
        return NULL;
@@ -178,12 +178,12 @@ gtk_source_completion_provider_get_name (GtkSourceCompletionProvider *provider)
  * gtk_source_completion_provider_get_icon:
  * @provider: The #GtkSourceCompletionProvider
  *
- * Get the #GdkPixbuf for the icon of the @provider.
+ * Get the #GdkTexture for the icon of the @provider.
  *
  * Returns: (nullable) (transfer none): The icon to be used for the provider,
  *          or %NULL if the provider does not have a special icon.
  */
-GdkPixbuf *
+GdkTexture *
 gtk_source_completion_provider_get_icon (GtkSourceCompletionProvider *provider)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_COMPLETION_PROVIDER (provider), NULL);
diff --git a/gtksourceview/gtksourcecompletionprovider.h b/gtksourceview/gtksourcecompletionprovider.h
index 4c1c05ad..5dcf5a41 100644
--- a/gtksourceview/gtksourcecompletionprovider.h
+++ b/gtksourceview/gtksourcecompletionprovider.h
@@ -74,7 +74,7 @@ struct _GtkSourceCompletionProviderInterface
        GTypeInterface g_iface;
 
        gchar                         *(*get_name)              (GtkSourceCompletionProvider *provider);
-       GdkPixbuf                     *(*get_icon)              (GtkSourceCompletionProvider *provider);
+       GdkTexture                    *(*get_icon)              (GtkSourceCompletionProvider *provider);
        const gchar                   *(*get_icon_name)         (GtkSourceCompletionProvider *provider);
        GIcon                         *(*get_gicon)             (GtkSourceCompletionProvider *provider);
        void                           (*populate)              (GtkSourceCompletionProvider *provider,
@@ -101,7 +101,7 @@ struct _GtkSourceCompletionProviderInterface
 GTK_SOURCE_AVAILABLE_IN_ALL
 gchar                         *gtk_source_completion_provider_get_name              
(GtkSourceCompletionProvider *provider);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GdkPixbuf                     *gtk_source_completion_provider_get_icon              
(GtkSourceCompletionProvider *provider);
+GdkTexture                    *gtk_source_completion_provider_get_icon              
(GtkSourceCompletionProvider *provider);
 GTK_SOURCE_AVAILABLE_IN_3_18
 const gchar                   *gtk_source_completion_provider_get_icon_name         
(GtkSourceCompletionProvider *provider);
 GTK_SOURCE_AVAILABLE_IN_3_18


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