[gnome-software/wip/hughsie/cairo_surface_t] Use cairo_surface_t rather than the deprecated GdkPixbuf for exported API
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/cairo_surface_t] Use cairo_surface_t rather than the deprecated GdkPixbuf for exported API
- Date: Mon, 26 Nov 2018 16:30:01 +0000 (UTC)
commit 967c181f0cc725b6b2213904fe0d6f448aab6f46
Author: Richard Hughes <richard hughsie com>
Date: Mon Nov 26 16:28:41 2018 +0000
Use cairo_surface_t rather than the deprecated GdkPixbuf for exported API
Note: we're still using GdkPixbuf as a file loader as cairo can only really
import PNGs rather than all the types supported in AppStream.
lib/gs-app.c | 31 ++++++++++++-----------
lib/gs-app.h | 7 +++---
lib/gs-utils.h | 3 +++
plugins/core/gs-plugin-icons.c | 40 +++++++++++++++++-------------
plugins/core/gs-plugin-key-colors.c | 41 ++++++++++++-------------------
plugins/core/gs-self-test.c | 1 +
plugins/dummy/gs-plugin-dummy.c | 4 +--
plugins/dummy/gs-self-test.c | 5 ++--
plugins/epiphany/gs-self-test.c | 3 ++-
plugins/flatpak/gs-flatpak.c | 6 ++++-
plugins/flatpak/gs-self-test.c | 3 ++-
plugins/packagekit/gs-plugin-packagekit.c | 2 +-
plugins/snap/gs-plugin-snap.c | 9 ++++---
plugins/snap/gs-self-test.c | 8 +++---
src/gs-app-row.c | 6 ++---
src/gs-details-page.c | 8 +++---
src/gs-editor.c | 9 ++++---
src/gs-popular-tile.c | 4 +--
src/gs-shell-search-provider.c | 12 ++++++---
src/gs-summary-tile.c | 8 +++---
src/gs-update-dialog.c | 8 +++---
21 files changed, 120 insertions(+), 98 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 77b3862b..2e6fc2df 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -124,7 +124,7 @@ typedef struct
GsApp *runtime;
GFile *local_file;
AsContentRating *content_rating;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *icon;
GsPrice *price;
GCancellable *cancellable;
GsPluginAction pending_action;
@@ -454,8 +454,8 @@ gs_app_to_string_append (GsApp *app, GString *str)
gs_app_get_kudos_percentage (app));
if (priv->name != NULL)
gs_app_kv_lpad (str, "name", priv->name);
- if (priv->pixbuf != NULL)
- gs_app_kv_printf (str, "pixbuf", "%p", priv->pixbuf);
+ if (priv->icon != NULL)
+ gs_app_kv_printf (str, "icon", "%p", priv->icon);
for (i = 0; i < priv->icons->len; i++) {
AsIcon *icon = g_ptr_array_index (priv->icons, i);
gs_app_kv_lpad (str, "icon-kind",
@@ -1643,21 +1643,21 @@ gs_app_set_developer_name (GsApp *app, const gchar *developer_name)
}
/**
- * gs_app_get_pixbuf:
+ * gs_app_get_icon:
* @app: a #GsApp
*
- * Gets a pixbuf to represent the application.
+ * Gets an icon to represent the application.
*
* Returns: (transfer none): a #GdkPixbuf, or %NULL
*
* Since: 3.22
**/
-GdkPixbuf *
-gs_app_get_pixbuf (GsApp *app)
+cairo_surface_t *
+gs_app_get_icon (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_return_val_if_fail (GS_IS_APP (app), NULL);
- return priv->pixbuf;
+ return priv->icon;
}
/**
@@ -1855,22 +1855,25 @@ gs_app_set_runtime (GsApp *app, GsApp *runtime)
}
/**
- * gs_app_set_pixbuf:
+ * gs_app_set_icon:
* @app: a #GsApp
* @pixbuf: a #GdkPixbuf, or %NULL
*
- * Sets a pixbuf used to represent the application.
+ * Sets a icon used to represent the application.
*
* Since: 3.22
**/
void
-gs_app_set_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
+gs_app_set_icon (GsApp *app, cairo_surface_t *icon)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
+ g_return_if_fail (icon != NULL);
locker = g_mutex_locker_new (&priv->mutex);
- g_set_object (&priv->pixbuf, pixbuf);
+ if (priv->icon != NULL)
+ cairo_surface_destroy (priv->icon);
+ priv->icon = cairo_surface_reference (icon);
}
/**
@@ -4196,8 +4199,8 @@ gs_app_finalize (GObject *object)
g_object_unref (priv->local_file);
if (priv->content_rating != NULL)
g_object_unref (priv->content_rating);
- if (priv->pixbuf != NULL)
- g_object_unref (priv->pixbuf);
+ if (priv->icon != NULL)
+ cairo_surface_destroy (priv->icon);
if (priv->price != NULL)
g_object_unref (priv->price);
diff --git a/lib/gs-app.h b/lib/gs-app.h
index fe04601a..92bf54a7 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -25,7 +25,6 @@
#include <glib-object.h>
#include <gdk/gdk.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
#include <appstream-glib.h>
#include "gs-price.h"
@@ -261,9 +260,9 @@ void gs_app_set_update_urgency (GsApp *app,
const gchar *gs_app_get_management_plugin (GsApp *app);
void gs_app_set_management_plugin (GsApp *app,
const gchar *management_plugin);
-GdkPixbuf *gs_app_get_pixbuf (GsApp *app);
-void gs_app_set_pixbuf (GsApp *app,
- GdkPixbuf *pixbuf);
+cairo_surface_t *gs_app_get_icon (GsApp *app);
+void gs_app_set_icon (GsApp *app,
+ cairo_surface_t *icon);
GsPrice *gs_app_get_price (GsApp *app);
void gs_app_set_price (GsApp *app,
gdouble amount,
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index 6fb98ff1..f0f0534f 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -30,6 +30,9 @@
G_BEGIN_DECLS
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(cairo_surface_t, cairo_surface_destroy)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(cairo_t, cairo_destroy)
+
/**
* GsUtilsCacheFlags:
* @GS_UTILS_CACHE_FLAG_NONE: No flags set
diff --git a/plugins/core/gs-plugin-icons.c b/plugins/core/gs-plugin-icons.c
index 164492f8..070ccd5f 100644
--- a/plugins/core/gs-plugin-icons.c
+++ b/plugins/core/gs-plugin-icons.c
@@ -120,10 +120,10 @@ gs_plugin_icons_download (GsPlugin *plugin,
return TRUE;
}
-static GdkPixbuf *
+static cairo_surface_t *
gs_plugin_icons_load_local (GsPlugin *plugin, AsIcon *icon, GError **error)
{
- GdkPixbuf *pixbuf;
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
gint size;
if (as_icon_get_filename (icon) == NULL) {
g_set_error_literal (error,
@@ -139,7 +139,9 @@ gs_plugin_icons_load_local (GsPlugin *plugin, AsIcon *icon, GError **error)
gs_utils_error_convert_gdk_pixbuf (error);
return NULL;
}
- return pixbuf;
+ return gdk_cairo_surface_create_from_pixbuf (pixbuf,
+ gs_plugin_get_scale (plugin),
+ NULL);
}
static gchar *
@@ -154,7 +156,7 @@ gs_plugin_icons_get_cache_fn (AsIcon *icon)
return g_strdup_printf ("%s-%s", checksum, basename);
}
-static GdkPixbuf *
+static cairo_surface_t *
gs_plugin_icons_load_remote (GsPlugin *plugin, AsIcon *icon, GError **error)
{
const gchar *fn;
@@ -223,13 +225,13 @@ gs_plugin_icons_add_theme_path (GsPlugin *plugin, const gchar *path)
}
}
-static GdkPixbuf *
+static cairo_surface_t *
gs_plugin_icons_load_stock (GsPlugin *plugin, AsIcon *icon, GError **error)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
- GdkPixbuf *pixbuf;
gint size;
g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->icon_theme_lock);
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
/* required */
if (as_icon_get_name (icon) == NULL) {
@@ -251,10 +253,12 @@ gs_plugin_icons_load_stock (GsPlugin *plugin, AsIcon *icon, GError **error)
gs_utils_error_convert_gdk_pixbuf (error);
return NULL;
}
- return pixbuf;
+ return gdk_cairo_surface_create_from_pixbuf (pixbuf,
+ gs_plugin_get_scale (plugin),
+ NULL);
}
-static GdkPixbuf *
+static cairo_surface_t *
gs_plugin_icons_load_cached (GsPlugin *plugin, AsIcon *icon, GError **error)
{
if (!as_icon_load (icon, AS_ICON_LOAD_FLAG_SEARCH_SIZE, error)) {
@@ -262,7 +266,9 @@ gs_plugin_icons_load_cached (GsPlugin *plugin, AsIcon *icon, GError **error)
gs_utils_error_convert_appstream (error);
return NULL;
}
- return g_object_ref (as_icon_get_pixbuf (icon));
+ return gdk_cairo_surface_create_from_pixbuf (as_icon_get_pixbuf (icon),
+ gs_plugin_get_scale (plugin),
+ NULL);
}
gboolean
@@ -280,29 +286,29 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
/* invalid */
- if (gs_app_get_pixbuf (app) != NULL)
+ if (gs_app_get_icon (app) != NULL)
return TRUE;
/* process all icons */
icons = gs_app_get_icons (app);
for (i = 0; i < icons->len; i++) {
AsIcon *icon = g_ptr_array_index (icons, i);
- g_autoptr(GdkPixbuf) pixbuf = NULL;
+ g_autoptr(cairo_surface_t) surface = NULL;
g_autoptr(GError) error_local = NULL;
/* handle different icon types */
switch (as_icon_get_kind (icon)) {
case AS_ICON_KIND_LOCAL:
- pixbuf = gs_plugin_icons_load_local (plugin, icon, &error_local);
+ surface = gs_plugin_icons_load_local (plugin, icon, &error_local);
break;
case AS_ICON_KIND_STOCK:
- pixbuf = gs_plugin_icons_load_stock (plugin, icon, &error_local);
+ surface = gs_plugin_icons_load_stock (plugin, icon, &error_local);
break;
case AS_ICON_KIND_REMOTE:
- pixbuf = gs_plugin_icons_load_remote (plugin, icon, &error_local);
+ surface = gs_plugin_icons_load_remote (plugin, icon, &error_local);
break;
case AS_ICON_KIND_CACHED:
- pixbuf = gs_plugin_icons_load_cached (plugin, icon, &error_local);
+ surface = gs_plugin_icons_load_cached (plugin, icon, &error_local);
break;
default:
g_set_error (&error_local,
@@ -312,8 +318,8 @@ gs_plugin_refine_app (GsPlugin *plugin,
as_icon_kind_to_string (as_icon_get_kind (icon)));
break;
}
- if (pixbuf != NULL) {
- gs_app_set_pixbuf (app, pixbuf);
+ if (surface != NULL) {
+ gs_app_set_icon (app, surface);
break;
}
diff --git a/plugins/core/gs-plugin-key-colors.c b/plugins/core/gs-plugin-key-colors.c
index 201ebebe..31fd585c 100644
--- a/plugins/core/gs-plugin-key-colors.c
+++ b/plugins/core/gs-plugin-key-colors.c
@@ -69,29 +69,25 @@ _convert_from_rgb8 (guchar val)
}
static void
-gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
+gs_plugin_key_colors_set_for_pixbuf (GsApp *app, cairo_surface_t *pb, guint number)
{
gint rowstride, n_channels;
- gint x, y;
- guchar *pixels, *p;
- guint bin_size = 200;
- guint i;
- guint number_of_bins;
- g_autoptr(AsImage) im = NULL;
+ guchar *pixels;
/* go through each pixel */
- n_channels = gdk_pixbuf_get_n_channels (pb);
- rowstride = gdk_pixbuf_get_rowstride (pb);
- pixels = gdk_pixbuf_get_pixels (pb);
- for (bin_size = 250; bin_size > 0; bin_size -= 2) {
+ n_channels = 1; //FIXME?
+ rowstride = cairo_image_surface_get_stride (pb);
+ pixels = cairo_image_surface_get_data (pb);
+ for (guint bin_size = 250; bin_size > 0; bin_size -= 2) {
g_autoptr(GHashTable) hash = NULL;
hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
NULL, g_free);
- for (y = 0; y < gdk_pixbuf_get_height (pb); y++) {
- for (x = 0; x < gdk_pixbuf_get_width (pb); x++) {
+ for (gint y = 0; y < cairo_image_surface_get_height (pb); y++) {
+ for (gint x = 0; x < cairo_image_surface_get_width (pb); x++) {
CdColorRGB8 tmp;
GsColorBin *s;
gpointer key;
+ guchar *p;
/* disregard any with alpha */
p = pixels + y * rowstride + x * n_channels;
@@ -122,10 +118,7 @@ gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
g_hash_table_insert (hash, key, s);
}
}
-
- number_of_bins = g_hash_table_size (hash);
-// g_debug ("number of colors: %i", number_of_bins);
- if (number_of_bins >= number) {
+ if (g_hash_table_size (hash) >= number) {
g_autoptr(GList) values = NULL;
/* order by most popular */
@@ -144,7 +137,7 @@ gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
}
/* the algorithm failed, so just return a monochrome ramp */
- for (i = 0; i < 3; i++) {
+ for (guint i = 0; i < 3; i++) {
g_autofree GdkRGBA *color = g_new0 (GdkRGBA, 1);
color->red = (gdouble) i / 3.f;
color->green = color->red;
@@ -161,8 +154,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GdkPixbuf *pb;
- g_autoptr(GdkPixbuf) pb_small = NULL;
+ cairo_surface_t *icon;
/* add a rating */
if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS) == 0)
@@ -173,14 +165,13 @@ gs_plugin_refine_app (GsPlugin *plugin,
return TRUE;
/* no pixbuf */
- pb = gs_app_get_pixbuf (app);
- if (pb == NULL) {
- g_debug ("no pixbuf, so no key colors");
+ icon = gs_app_get_icon (app);
+ if (icon == NULL) {
+ g_debug ("no icon, so no key colors");
return TRUE;
}
/* get a list of key colors */
- pb_small = gdk_pixbuf_scale_simple (pb, 32, 32, GDK_INTERP_BILINEAR);
- gs_plugin_key_colors_set_for_pixbuf (app, pb_small, 10);
+ gs_plugin_key_colors_set_for_pixbuf (app, icon, 10);
return TRUE;
}
diff --git a/plugins/core/gs-self-test.c b/plugins/core/gs-self-test.c
index 3ca6adcc..52a4a9be 100644
--- a/plugins/core/gs-self-test.c
+++ b/plugins/core/gs-self-test.c
@@ -207,6 +207,7 @@ main (int argc, char **argv)
NULL
};
+ gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
g_setenv ("GS_SELF_TEST_CACHEDIR", tmp_root, TRUE);
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index dd657027..91d46d75 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -753,7 +753,7 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, "http://www.box.org");
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
- gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png", NULL));
+ gs_app_set_icon (app, cairo_image_surface_create_from_png
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png"));
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
gs_app_list_add (list, app);
@@ -773,7 +773,7 @@ gs_plugin_add_recent (GsPlugin *plugin,
gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, "http://www.box.org");
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
- gs_app_set_pixbuf (app, gdk_pixbuf_new_from_file
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png", NULL));
+ gs_app_set_icon (app, cairo_image_surface_create_from_png
("/usr/share/icons/hicolor/48x48/apps/chiron.desktop.png"));
gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
gs_app_list_add (list, app);
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 1708a0b5..53d50661 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -386,7 +386,7 @@ gs_plugins_dummy_installed_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
g_assert_cmpstr (gs_app_get_name (app), ==, "Zeus");
g_assert_cmpstr (gs_app_get_source_default (app), ==, "zeus");
- g_assert (gs_app_get_pixbuf (app) != NULL);
+ g_assert (gs_app_get_icon (app) != NULL);
/* check various bitfields */
g_assert (gs_app_has_quirk (app, GS_APP_QUIRK_PROVENANCE));
@@ -415,7 +415,7 @@ gs_plugins_dummy_installed_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (gs_app_get_source_default (addon), ==, "zeus-spell");
g_assert_cmpstr (gs_app_get_license (addon), ==,
"LicenseRef-free=https://www.debian.org/");
- g_assert (gs_app_get_pixbuf (addon) == NULL);
+ g_assert (gs_app_get_icon (addon) == NULL);
}
static void
@@ -851,6 +851,7 @@ main (int argc, char **argv)
NULL
};
+ gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
g_setenv ("GS_XMLB_VERBOSE", "1", TRUE);
diff --git a/plugins/epiphany/gs-self-test.c b/plugins/epiphany/gs-self-test.c
index 47013486..635db31d 100644
--- a/plugins/epiphany/gs-self-test.c
+++ b/plugins/epiphany/gs-self-test.c
@@ -50,7 +50,7 @@ gs_plugins_epiphany_func (GsPluginLoader *plugin_loader)
g_assert (ret);
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
- g_assert (gs_app_get_pixbuf (app) != NULL);
+ g_assert (gs_app_get_icon (app) != NULL);
}
int
@@ -68,6 +68,7 @@ main (int argc, char **argv)
NULL
};
+ gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
g_setenv ("GS_XMLB_VERBOSE", "1", TRUE);
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 28c2b899..2ba116ac 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2326,13 +2326,17 @@ gs_flatpak_file_to_app_bundle (GsFlatpak *self,
if (icon_data != NULL) {
g_autoptr(GInputStream) stream_icon = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
+ g_autoptr(cairo_surface_t) surface = NULL;
stream_icon = g_memory_input_stream_new_from_bytes (icon_data);
pixbuf = gdk_pixbuf_new_from_stream (stream_icon, cancellable, error);
if (pixbuf == NULL) {
gs_utils_error_convert_gdk_pixbuf (error);
return NULL;
}
- gs_app_set_pixbuf (app, pixbuf);
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf,
+ gs_plugin_get_scale (self->plugin),
+ NULL);
+ gs_app_set_icon (app, surface);
} else {
g_autoptr(AsIcon) icon = NULL;
icon = as_icon_new ();
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 933d70e0..80535b88 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -151,7 +151,7 @@ gs_plugins_flatpak_repo_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (gs_app_get_description (app), ==,
"Longer multiline comment that does into detail.");
g_assert (gs_app_get_local_file (app) != NULL);
- g_assert (gs_app_get_pixbuf (app) != NULL);
+ g_assert (gs_app_get_icon (app) != NULL);
/* now install the remote */
g_object_unref (plugin_job);
@@ -1723,6 +1723,7 @@ main (int argc, char **argv)
NULL
};
+ gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
g_setenv ("GS_XMLB_VERBOSE", "1", TRUE);
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 096fbd0d..b7e9d5ec 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -414,7 +414,7 @@ gs_plugin_app_install (GsPlugin *plugin,
/* get the new icon from the package */
gs_app_set_local_file (app, NULL);
gs_app_add_icon (app, NULL);
- gs_app_set_pixbuf (app, NULL);
+ gs_app_set_icon (app, NULL);
break;
default:
g_set_error (error,
diff --git a/plugins/snap/gs-plugin-snap.c b/plugins/snap/gs-plugin-snap.c
index 739fbe4d..cfe6e366 100644
--- a/plugins/snap/gs-plugin-snap.c
+++ b/plugins/snap/gs-plugin-snap.c
@@ -621,6 +621,7 @@ load_snap_icon (GsApp *app, SnapdClient *client, SnapdSnap *snap, GCancellable *
g_autoptr(GInputStream) input_stream = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
g_autoptr(GError) error = NULL;
+ g_autoptr(cairo_surface_t) surface = NULL;
icon_url = snapd_snap_get_icon (snap);
if (icon_url == NULL || strcmp (icon_url, "") == 0)
@@ -638,8 +639,10 @@ load_snap_icon (GsApp *app, SnapdClient *client, SnapdSnap *snap, GCancellable *
g_warning ("Failed to decode snap icon %s: %s", icon_url, error->message);
return FALSE;
}
- gs_app_set_pixbuf (app, pixbuf);
-
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf,
+ gs_plugin_get_scale (plugin),
+ NULL);
+ gs_app_set_icon (app, surface);
return TRUE;
}
@@ -885,7 +888,7 @@ gs_plugin_refine_app (GsPlugin *plugin,
}
/* load icon if requested */
- if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON && gs_app_get_pixbuf (app) == NULL)
+ if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON && gs_app_get_icon (app) == NULL)
load_icon (plugin, client, app, gs_app_get_metadata_item (app, "snap::name"), local_snap,
store_snap, cancellable);
return TRUE;
diff --git a/plugins/snap/gs-self-test.c b/plugins/snap/gs-self-test.c
index 6988be40..37a2748b 100644
--- a/plugins/snap/gs-self-test.c
+++ b/plugins/snap/gs-self-test.c
@@ -238,7 +238,7 @@ gs_plugins_snap_test_func (GsPluginLoader *plugin_loader)
GPtrArray *screenshots, *images;
AsScreenshot *screenshot;
AsImage *image;
- GdkPixbuf *pixbuf;
+ cairo_surface_t *icon;
g_autoptr(GError) error = NULL;
/* no snap, abort */
@@ -277,9 +277,9 @@ gs_plugins_snap_test_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (as_image_get_url (image), ==, "http://example.com/screenshot2.jpg");
g_assert_cmpint (as_image_get_width (image), ==, 1024);
g_assert_cmpint (as_image_get_height (image), ==, 768);
- pixbuf = gs_app_get_pixbuf (app);
- g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, 1);
- g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, 1);
+ icon = gs_app_get_icon (app);
+ g_assert_cmpint (cairo_image_surface_get_width (icon), ==, 1);
+ g_assert_cmpint (cairo_image_surface_get_height (icon), ==, 1);
g_assert_cmpint (gs_app_get_size_installed (app), ==, 0);
g_assert_cmpint (gs_app_get_size_download (app), ==, 500);
g_assert_cmpint (gs_app_get_install_date (app), ==, 0);
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 9d0fba98..3411713d 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -411,9 +411,9 @@ gs_app_row_refresh (GsAppRow *app_row)
}
/* pixbuf */
- if (gs_app_get_pixbuf (priv->app) != NULL)
- gs_image_set_from_pixbuf (GTK_IMAGE (priv->image),
- gs_app_get_pixbuf (priv->app));
+ if (gs_app_get_icon (priv->app) != NULL)
+ gtk_image_set_from_surface (GTK_IMAGE (priv->image),
+ gs_app_get_icon (priv->app));
context = gtk_widget_get_style_context (priv->image);
if (missing_search_result)
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 789960c4..48cfedc2 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -948,7 +948,7 @@ static void
gs_details_page_refresh_all (GsDetailsPage *self)
{
GsAppList *history;
- GdkPixbuf *pixbuf = NULL;
+ cairo_surface_t *icon = NULL;
GList *addons;
GtkWidget *widget;
const gchar *tmp;
@@ -987,9 +987,9 @@ gs_details_page_refresh_all (GsDetailsPage *self)
gs_details_page_set_description (self, tmp);
/* set the icon */
- pixbuf = gs_app_get_pixbuf (self->app);
- if (pixbuf != NULL) {
- gs_image_set_from_pixbuf (GTK_IMAGE (self->application_details_icon), pixbuf);
+ icon = gs_app_get_icon (self->app);
+ if (icon != NULL) {
+ gtk_image_set_from_surface (GTK_IMAGE (self->application_details_icon), icon);
gtk_widget_set_visible (self->application_details_icon, TRUE);
} else {
gtk_widget_set_visible (self->application_details_icon, FALSE);
diff --git a/src/gs-editor.c b/src/gs-editor.c
index 10d1d4ca..9780f1e3 100644
--- a/src/gs-editor.c
+++ b/src/gs-editor.c
@@ -83,12 +83,13 @@ static void
gs_editor_refine_app_pixbuf (GsApp *app)
{
GPtrArray *icons;
- if (gs_app_get_pixbuf (app) != NULL)
+ if (gs_app_get_icon (app) != NULL)
return;
icons = gs_app_get_icons (app);
for (guint i = 0; i < icons->len; i++) {
AsIcon *ic = g_ptr_array_index (icons, i);
g_autoptr(GError) error = NULL;
+ g_autoptr(cairo_surface_t) surface = NULL;
if (as_icon_get_kind (ic) == AS_ICON_KIND_STOCK) {
g_autoptr(GdkPixbuf) pb = NULL;
@@ -101,13 +102,15 @@ gs_editor_refine_app_pixbuf (GsApp *app)
g_warning ("failed to load icon: %s", error->message);
continue;
}
- gs_app_set_pixbuf (app, pb);
+ surface = gdk_cairo_surface_create_from_pixbuf (pb, 1, NULL);
+ gs_app_set_icon (app, surface);
} else {
if (!as_icon_load (ic, AS_ICON_LOAD_FLAG_SEARCH_SIZE, &error)) {
g_warning ("failed to load icon: %s", error->message);
continue;
}
- gs_app_set_pixbuf (app, as_icon_get_pixbuf (ic));
+ surface = gdk_cairo_surface_create_from_pixbuf (as_icon_get_pixbuf (ic), 1, NULL);
+ gs_app_set_icon (app, surface);
}
break;
}
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index 9ef9a4cb..08e05af2 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -133,8 +133,8 @@ gs_popular_tile_set_app (GsAppTile *app_tile, GsApp *app)
css = gs_app_get_metadata_item (app, "GnomeSoftware::PopularTile-css");
gs_utils_widget_set_css (GTK_WIDGET (tile), css);
- if (gs_app_get_pixbuf (tile->app) != NULL) {
- gs_image_set_from_pixbuf (GTK_IMAGE (tile->image), gs_app_get_pixbuf (tile->app));
+ if (gs_app_get_icon (tile->app) != NULL) {
+ gtk_image_set_from_surface (GTK_IMAGE (tile->image), gs_app_get_icon (tile->app));
} else {
gtk_image_set_from_icon_name (GTK_IMAGE (tile->image),
"application-x-executable",
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 88bec30b..5cd6399c 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -236,7 +236,6 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
GsShellSearchProvider *self = user_data;
GVariantBuilder meta;
GVariant *meta_variant;
- GdkPixbuf *pixbuf;
gint i;
GVariantBuilder builder;
@@ -244,6 +243,7 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
for (i = 0; results[i]; i++) {
GsApp *app;
+ cairo_surface_t *icon;
g_autofree gchar *description = NULL;
/* already built */
@@ -260,9 +260,15 @@ handle_get_result_metas (GsShellSearchProvider2 *skeleton,
g_variant_builder_init (&meta, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&meta, "{sv}", "id", g_variant_new_string (gs_app_get_unique_id
(app)));
g_variant_builder_add (&meta, "{sv}", "name", g_variant_new_string (gs_app_get_name (app)));
- pixbuf = gs_app_get_pixbuf (app);
- if (pixbuf != NULL)
+ icon = gs_app_get_icon (app);
+ if (icon != NULL) {
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
+ pixbuf = gdk_pixbuf_get_from_surface (icon,
+ 0, 0,
+ cairo_image_surface_get_width (icon),
+ cairo_image_surface_get_height (icon));
g_variant_builder_add (&meta, "{sv}", "icon", g_icon_serialize (G_ICON (pixbuf)));
+ }
if (gs_utils_list_has_app_fuzzy (self->search_results, app) &&
gs_app_get_origin_hostname (app) != NULL) {
diff --git a/src/gs-summary-tile.c b/src/gs-summary-tile.c
index 26506350..bd6e77a8 100644
--- a/src/gs-summary-tile.c
+++ b/src/gs-summary-tile.c
@@ -111,7 +111,7 @@ app_state_changed (GsApp *app, GParamSpec *pspec, GsSummaryTile *tile)
static void
gs_summary_tile_set_app (GsAppTile *app_tile, GsApp *app)
{
- const GdkPixbuf *pixbuf;
+ cairo_surface_t *icon;
GsSummaryTile *tile = GS_SUMMARY_TILE (app_tile);
const gchar *css;
g_autofree gchar *text = NULL;
@@ -139,9 +139,9 @@ gs_summary_tile_set_app (GsAppTile *app_tile, GsApp *app)
G_CALLBACK (app_state_changed), tile);
app_state_changed (tile->app, NULL, tile);
- pixbuf = gs_app_get_pixbuf (app);
- if (pixbuf != NULL) {
- gs_image_set_from_pixbuf (GTK_IMAGE (tile->image), pixbuf);
+ icon = gs_app_get_icon (app);
+ if (icon != NULL) {
+ gtk_image_set_from_surface (GTK_IMAGE (tile->image), icon);
} else {
gtk_image_set_from_icon_name (GTK_IMAGE (tile->image),
"application-x-executable",
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 29a349b9..1a3fc413 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -100,7 +100,7 @@ static void
set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
{
AsAppKind kind;
- const GdkPixbuf *pixbuf;
+ cairo_surface_t *icon;
const gchar *update_details;
/* set window title */
@@ -134,9 +134,9 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
gtk_label_set_label (GTK_LABEL (dialog->label_name), gs_app_get_name (app));
gtk_label_set_label (GTK_LABEL (dialog->label_summary), gs_app_get_summary (app));
- pixbuf = gs_app_get_pixbuf (app);
- if (pixbuf != NULL)
- gs_image_set_from_pixbuf (GTK_IMAGE (dialog->image_icon), pixbuf);
+ icon = gs_app_get_icon (app);
+ if (icon != NULL)
+ gtk_image_set_from_surface (GTK_IMAGE (dialog->image_icon), icon);
/* show the back button if needed */
gtk_widget_set_visible (dialog->button_back, !g_queue_is_empty (dialog->back_entry_stack));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]