summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2023-02-09 12:18:01 +0100
committerMarge Bot <marge-bot@gnome.org>2023-02-22 12:21:36 +0000
commitf7429db961417ef278e8a16b61bcd3fd4e02b1b4 (patch)
tree45c13aa95154e838ef29ebe7a9e65b63a737e584
parentfdc4736eae691a6adfba837f42d642258533ddc1 (diff)
downloadepiphany-f7429db961417ef278e8a16b61bcd3fd4e02b1b4.tar.gz
Favicons are now GdkTexture instead of cairo_surface_t
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1281>
-rw-r--r--embed/ephy-web-view.c13
-rw-r--r--embed/ephy-web-view.h2
-rw-r--r--lib/ephy-favicon-helpers.c33
-rw-r--r--lib/ephy-favicon-helpers.h6
-rw-r--r--lib/ephy-suggestion.c13
-rw-r--r--src/bookmarks/ephy-bookmark-row.c18
-rw-r--r--src/ephy-action-bar-start.c14
-rw-r--r--src/ephy-history-dialog.c16
-rw-r--r--src/ephy-page-row.c2
-rw-r--r--src/ephy-suggestion-model.c22
-rw-r--r--src/ephy-tab-view.c2
-rw-r--r--src/synced-tabs-dialog.c9
-rw-r--r--src/window-commands.c84
13 files changed, 129 insertions, 105 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index b318aa8c8..58cbc982b 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -89,7 +89,7 @@ struct _EphyWebView {
char *last_committed_address;
char *loading_message;
char *link_message;
- GdkPixbuf *icon;
+ GIcon *icon;
/* Reader mode */
gboolean entering_reader_mode;
@@ -515,10 +515,11 @@ _ephy_web_view_update_icon (EphyWebView *view)
g_clear_object (&view->icon);
if (view->address) {
- cairo_surface_t *icon_surface = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (view));
- if (icon_surface) {
+ GdkTexture *icon_texture = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (view));
+
+ if (icon_texture) {
gint scale = gtk_widget_get_scale_factor (GTK_WIDGET (view));
- view->icon = ephy_pixbuf_get_from_surface_scaled (icon_surface, scale * FAVICON_SIZE, scale * FAVICON_SIZE);
+ view->icon = ephy_favicon_get_from_texture_scaled (icon_texture, scale * FAVICON_SIZE, scale * FAVICON_SIZE);
}
}
@@ -2716,7 +2717,7 @@ ephy_web_view_load_failed (EphyWebView *view)
*
* Return value: (transfer none): a the view's site icon
**/
-GdkPixbuf *
+GIcon *
ephy_web_view_get_icon (EphyWebView *view)
{
return view->icon;
@@ -3889,7 +3890,7 @@ ephy_web_view_class_init (EphyWebViewClass *klass)
obj_properties[PROP_ICON] =
g_param_spec_object ("icon",
NULL, NULL,
- GDK_TYPE_PIXBUF,
+ G_TYPE_ICON,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index 09d6fb11f..97d74d0e5 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -87,7 +87,7 @@ void ephy_web_view_load_url (EphyWebView
const char *url);
gboolean ephy_web_view_is_loading (EphyWebView *view);
gboolean ephy_web_view_load_failed (EphyWebView *view);
-GdkPixbuf * ephy_web_view_get_icon (EphyWebView *view);
+GIcon * ephy_web_view_get_icon (EphyWebView *view);
EphyWebViewDocumentType ephy_web_view_get_document_type (EphyWebView *view);
EphyWebViewNavigationFlags ephy_web_view_get_navigation_flags (EphyWebView *view);
const char * ephy_web_view_get_status_message (EphyWebView *view);
diff --git a/lib/ephy-favicon-helpers.c b/lib/ephy-favicon-helpers.c
index 148ac1cf6..94436d518 100644
--- a/lib/ephy-favicon-helpers.c
+++ b/lib/ephy-favicon-helpers.c
@@ -24,29 +24,28 @@
#include <gdk/gdk.h>
#include <glib.h>
-GdkPixbuf *
-ephy_pixbuf_get_from_surface_scaled (cairo_surface_t *surface,
- int width,
- int height)
+GIcon *
+ephy_favicon_get_from_texture_scaled (GdkTexture *texture,
+ int width,
+ int height)
{
- GdkPixbuf *pixbuf;
+ g_autoptr (GdkPixbuf) pixbuf = NULL;
int favicon_width;
int favicon_height;
- /* Treat NULL surface cleanly. */
- if (!surface)
+ /* Treat NULL texture cleanly. */
+ if (texture)
return NULL;
- favicon_width = cairo_image_surface_get_width (surface);
- favicon_height = cairo_image_surface_get_height (surface);
- pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, favicon_width, favicon_height);
-
/* A size of (0, 0) means the original size of the favicon. */
- if (width && height && (favicon_width != width || favicon_height != height)) {
- GdkPixbuf *scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
- g_object_unref (pixbuf);
- pixbuf = scaled_pixbuf;
- }
+ if (width == 0 && height == 0)
+ return G_ICON (g_object_ref (texture));
+
+ favicon_width = gdk_texture_get_width (texture);
+ favicon_height = gdk_texture_get_height (texture);
+ if (favicon_width == width && favicon_height == height)
+ return G_ICON (g_object_ref (texture));
- return pixbuf;
+ pixbuf = gdk_pixbuf_get_from_texture (texture);
+ return G_ICON (gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR));
}
diff --git a/lib/ephy-favicon-helpers.h b/lib/ephy-favicon-helpers.h
index 72a729fb4..e46e1761c 100644
--- a/lib/ephy-favicon-helpers.h
+++ b/lib/ephy-favicon-helpers.h
@@ -20,11 +20,11 @@
#pragma once
-#include <cairo.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdk.h>
+#include <glib.h>
G_BEGIN_DECLS
-GdkPixbuf *ephy_pixbuf_get_from_surface_scaled (cairo_surface_t *surface, int width, int height);
+GIcon *ephy_favicon_get_from_texture_scaled (GdkTexture *texture, int width, int height);
G_END_DECLS
diff --git a/lib/ephy-suggestion.c b/lib/ephy-suggestion.c
index 31201a8b4..b608c810a 100644
--- a/lib/ephy-suggestion.c
+++ b/lib/ephy-suggestion.c
@@ -75,6 +75,17 @@ ephy_suggestion_get_property (GObject *object,
}
}
+static void
+ephy_suggestion_finalize (GObject *object)
+{
+ EphySuggestion *self = EPHY_SUGGESTION (object);
+
+ g_free (self->unescaped_title);
+ g_clear_pointer (&self->favicon, cairo_surface_destroy);
+
+ G_OBJECT_CLASS (ephy_suggestion_parent_class)->finalize (object);
+}
+
char *
ephy_suggestion_replace_typed_text (DzlSuggestion *self,
const char *typed_text)
@@ -105,6 +116,7 @@ ephy_suggestion_class_init (EphySuggestionClass *klass)
object_class->get_property = ephy_suggestion_get_property;
object_class->set_property = ephy_suggestion_set_property;
+ object_class->finalize = ephy_suggestion_finalize;
dzl_suggestion_class->replace_typed_text = ephy_suggestion_replace_typed_text;
dzl_suggestion_class->get_icon_surface = ephy_suggestion_get_icon_surface;
@@ -207,6 +219,7 @@ void
ephy_suggestion_set_favicon (EphySuggestion *self,
cairo_surface_t *favicon)
{
+ g_clear_pointer (&self->favicon, cairo_surface_destroy);
self->favicon = favicon;
g_object_notify (G_OBJECT (self), "icon");
}
diff --git a/src/bookmarks/ephy-bookmark-row.c b/src/bookmarks/ephy-bookmark-row.c
index e7ce44dbd..45e46a025 100644
--- a/src/bookmarks/ephy-bookmark-row.c
+++ b/src/bookmarks/ephy-bookmark-row.c
@@ -98,22 +98,18 @@ ephy_bookmark_row_favicon_loaded_cb (GObject *source,
{
g_autoptr (EphyBookmarkRow) self = user_data;
WebKitFaviconDatabase *database = WEBKIT_FAVICON_DATABASE (source);
- cairo_surface_t *icon_surface;
- g_autoptr (GdkPixbuf) favicon = NULL;
+ g_autoptr (GdkTexture) icon_texture = NULL;
+ g_autoptr (GIcon) favicon = NULL;
g_assert (EPHY_IS_BOOKMARK_ROW (self));
- icon_surface = webkit_favicon_database_get_favicon_finish (database, result, NULL);
- if (icon_surface) {
+ icon_texture = webkit_favicon_database_get_favicon_finish (database, result, NULL);
+ if (icon_texture) {
int scale = gtk_widget_get_scale_factor (self->favicon_image);
- favicon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE * scale, FAVICON_SIZE * scale);
- cairo_surface_destroy (icon_surface);
- }
-
- if (favicon) {
- if (self->favicon_image != NULL)
- gtk_image_set_from_gicon (GTK_IMAGE (self->favicon_image), G_ICON (favicon));
+ favicon = ephy_favicon_get_from_texture_scaled (icon_texture, FAVICON_SIZE * scale, FAVICON_SIZE * scale);
+ if (favicon && self->favicon_image)
+ gtk_image_set_from_gicon (GTK_IMAGE (self->favicon_image), favicon);
}
}
diff --git a/src/ephy-action-bar-start.c b/src/ephy-action-bar-start.c
index 07109700f..475fba35d 100644
--- a/src/ephy-action-bar-start.c
+++ b/src/ephy-action-bar-start.c
@@ -171,19 +171,17 @@ icon_loaded_cb (GObject *source,
GtkWidget *image)
{
WebKitFaviconDatabase *database = WEBKIT_FAVICON_DATABASE (source);
- GdkPixbuf *favicon = NULL;
- cairo_surface_t *icon_surface = webkit_favicon_database_get_favicon_finish (database, result, NULL);
+ g_autoptr (GIcon) favicon = NULL;
+ g_autoptr (GdkTexture) icon_texture = webkit_favicon_database_get_favicon_finish (database, result, NULL);
- if (icon_surface) {
+ if (icon_texture) {
int scale = gtk_widget_get_scale_factor (image);
- favicon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE * scale, FAVICON_SIZE * scale);
- cairo_surface_destroy (icon_surface);
+ favicon = ephy_favicon_get_from_texture_scaled (icon_texture, FAVICON_SIZE * scale, FAVICON_SIZE * scale);
+ if (favicon)
+ gtk_image_set_from_gicon (GTK_IMAGE (image), favicon);
}
- if (favicon)
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), favicon);
-
g_object_unref (image);
}
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 9eb106ee5..01dc63da4 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -425,23 +425,21 @@ ephy_history_dialog_row_favicon_loaded_cb (GObject *source,
{
g_autoptr (GtkWidget) icon = user_data;
WebKitFaviconDatabase *database = WEBKIT_FAVICON_DATABASE (source);
- cairo_surface_t *icon_surface;
- g_autoptr (GdkPixbuf) favicon = NULL;
+ g_autoptr (GdkTexture) icon_texture = NULL;
+ g_autoptr (GIcon) favicon = NULL;
g_autoptr (GError) error = NULL;
- icon_surface = webkit_favicon_database_get_favicon_finish (database, result, &error);
+ icon_texture = webkit_favicon_database_get_favicon_finish (database, result, &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
- if (icon_surface) {
+ if (icon_texture) {
int scale = gtk_widget_get_scale_factor (icon);
- favicon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE * scale, FAVICON_SIZE * scale);
- cairo_surface_destroy (icon_surface);
+ favicon = ephy_favicon_get_from_texture_scaled (icon_texture, FAVICON_SIZE * scale, FAVICON_SIZE * scale);
+ if (favicon && icon)
+ gtk_image_set_from_gicon (GTK_IMAGE (icon), favicon);
}
-
- if (favicon && icon)
- gtk_image_set_from_gicon (GTK_IMAGE (icon), G_ICON (favicon));
}
static GtkWidget *
diff --git a/src/ephy-page-row.c b/src/ephy-page-row.c
index eb99c05b0..618921bbf 100644
--- a/src/ephy-page-row.c
+++ b/src/ephy-page-row.c
@@ -114,7 +114,7 @@ update_icon_cb (EphyPageRow *self)
{
EphyEmbed *embed = EPHY_EMBED (adw_tab_page_get_child (self->page));
EphyWebView *view = ephy_embed_get_web_view (embed);
- GIcon *icon = G_ICON (ephy_web_view_get_icon (view));
+ GIcon *icon = ephy_web_view_get_icon (view);
const char *uri, *favicon_name;
AdwTabView *tab_view;
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index 29321e9eb..b34e486bb 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -254,23 +254,27 @@ icon_loaded_cb (GObject *source,
{
WebKitFaviconDatabase *database = WEBKIT_FAVICON_DATABASE (source);
EphySuggestion *suggestion;
- GError *error = NULL;
+ g_autoptr (GdkTexture) texture = NULL;
cairo_surface_t *favicon;
gdouble x_scale, y_scale;
- int x, y;
+ int w, h;
- favicon = webkit_favicon_database_get_favicon_finish (database, result, &error);
-
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) || favicon == NULL)
+ texture = webkit_favicon_database_get_favicon_finish (database, result, NULL);
+ if (texture == NULL)
return;
suggestion = EPHY_SUGGESTION (user_data);
- x = cairo_image_surface_get_width (favicon);
- y = cairo_image_surface_get_height (favicon);
- x_scale = (gdouble)x / 16;
- y_scale = (gdouble)y / 16;
+ w = gdk_texture_get_width (texture);
+ h = gdk_texture_get_height (texture);
+ favicon = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
+ gdk_texture_download (texture,
+ cairo_image_surface_get_data (favicon),
+ cairo_image_surface_get_stride (favicon));
+ cairo_surface_mark_dirty (favicon);
+ x_scale = (gdouble)w / 16;
+ y_scale = (gdouble)h / 16;
cairo_surface_set_device_scale (favicon, x_scale, y_scale);
ephy_suggestion_set_favicon (suggestion, favicon);
diff --git a/src/ephy-tab-view.c b/src/ephy-tab-view.c
index 60b57dd4c..2933ef091 100644
--- a/src/ephy-tab-view.c
+++ b/src/ephy-tab-view.c
@@ -382,7 +382,7 @@ update_icon_cb (AdwTabPage *page)
{
EphyEmbed *embed = EPHY_EMBED (adw_tab_page_get_child (page));
EphyWebView *view = ephy_embed_get_web_view (embed);
- GIcon *icon = G_ICON (ephy_web_view_get_icon (view));
+ GIcon *icon = ephy_web_view_get_icon (view);
g_autoptr (GIcon) placeholder_icon = NULL;
const char *uri, *favicon_name;
diff --git a/src/synced-tabs-dialog.c b/src/synced-tabs-dialog.c
index e8bf95fcd..c6539bc4c 100644
--- a/src/synced-tabs-dialog.c
+++ b/src/synced-tabs-dialog.c
@@ -135,16 +135,13 @@ synced_tabs_dialog_favicon_loaded_cb (GObject *source,
{
WebKitFaviconDatabase *database = WEBKIT_FAVICON_DATABASE (source);
PopulateRowAsyncData *data = (PopulateRowAsyncData *)user_data;
- cairo_surface_t *surface;
+ g_autoptr (GdkTexture) texture = NULL;
g_autoptr (GIcon) favicon = NULL;
GtkTreeIter parent_iter;
char *escaped_url;
- surface = webkit_favicon_database_get_favicon_finish (database, result, NULL);
- if (surface) {
- favicon = G_ICON (ephy_pixbuf_get_from_surface_scaled (surface, FAVICON_SIZE, FAVICON_SIZE));
- cairo_surface_destroy (surface);
- }
+ texture = webkit_favicon_database_get_favicon_finish (database, result, NULL);
+ favicon = ephy_favicon_get_from_texture_scaled (texture, FAVICON_SIZE, FAVICON_SIZE);
gtk_tree_model_get_iter_first (data->dialog->treestore, &parent_iter);
for (guint i = 0; i < data->parent_index; i++)
diff --git a/src/window-commands.c b/src/window-commands.c
index dd0b93716..2e1f28346 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1529,12 +1529,51 @@ rounded_rectangle (cairo_t *cr,
}
static GdkPixbuf *
-frame_pixbuf (GdkPixbuf *pixbuf,
- GdkRGBA *rgba,
- int width,
- int height)
+scaled_pixbuf_from_icon (GIcon *icon,
+ int width,
+ int height)
+{
+ g_autoptr (GdkPixbuf) pixbuf = NULL;
+ int w, h;
+ GdkPixbuf *scaled;
+
+ if (!icon)
+ return NULL;
+
+ if (GDK_IS_PIXBUF (icon))
+ pixbuf = GDK_PIXBUF (g_object_ref (icon));
+ else if (GDK_IS_TEXTURE (icon))
+ pixbuf = gdk_pixbuf_get_from_texture (GDK_TEXTURE (icon));
+ else
+ g_assert_not_reached ();
+
+ w = gdk_pixbuf_get_width (pixbuf);
+ h = gdk_pixbuf_get_height (pixbuf);
+
+ if (w < 48 || h < 48) {
+ scaled = gdk_pixbuf_scale_simple (pixbuf, w * 3, h * 3, GDK_INTERP_NEAREST);
+ } else if (w > width || h > height) {
+ double ws, hs, s;
+
+ ws = (double)width / w;
+ hs = (double)height / h;
+ s = MIN (ws, hs);
+ scaled = gdk_pixbuf_scale_simple (pixbuf, w * s, h * s, GDK_INTERP_BILINEAR);
+ } else {
+ scaled = g_object_ref (pixbuf);
+ }
+
+ return scaled;
+}
+
+static GdkPixbuf *
+frame_pixbuf (GIcon *icon,
+ GdkRGBA *rgba,
+ int width,
+ int height)
{
GdkPixbuf *framed;
+ g_autoptr (GdkPixbuf) scaled = NULL;
cairo_surface_t *surface;
cairo_t *cr;
int frame_width;
@@ -1564,34 +1603,14 @@ frame_pixbuf (GdkPixbuf *pixbuf,
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3);
cairo_fill_preserve (cr);
- if (pixbuf != NULL) {
- GdkPixbuf *scaled;
- int w;
- int h;
-
- w = gdk_pixbuf_get_width (pixbuf);
- h = gdk_pixbuf_get_height (pixbuf);
-
- if (w < 48 || h < 48) {
- scaled = gdk_pixbuf_scale_simple (pixbuf, w * 3, h * 3, GDK_INTERP_NEAREST);
- } else if (w > width || h > height) {
- double ws, hs, s;
-
- ws = (double)width / w;
- hs = (double)height / h;
- s = MIN (ws, hs);
- scaled = gdk_pixbuf_scale_simple (pixbuf, w * s, h * s, GDK_INTERP_BILINEAR);
- } else {
- scaled = g_object_ref (pixbuf);
- }
-
- w = gdk_pixbuf_get_width (scaled);
- h = gdk_pixbuf_get_height (scaled);
+ scaled = scaled_pixbuf_from_icon (icon, width, height);
+ if (scaled != NULL) {
+ int w = gdk_pixbuf_get_width (scaled);
+ int h = gdk_pixbuf_get_height (scaled);
gdk_cairo_set_source_pixbuf (cr, scaled,
(width - w) / 2,
(height - h) / 2);
- g_object_unref (scaled);
cairo_fill (cr);
}
@@ -1607,11 +1626,10 @@ static void create_install_dialog_when_ready (EphyApplicationDialogData *data);
static void
set_image_from_favicon (EphyApplicationDialogData *data)
{
- g_autoptr (GdkPixbuf) icon = NULL;
- cairo_surface_t *icon_surface = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (data->view));
+ g_autoptr (GIcon) icon = NULL;
+ g_autoptr (GdkTexture) icon_texture = webkit_web_view_get_favicon (WEBKIT_WEB_VIEW (data->view));
- if (icon_surface)
- icon = ephy_pixbuf_get_from_surface_scaled (icon_surface, 0, 0);
+ icon = ephy_favicon_get_from_texture_scaled (icon_texture, 0, 0);
if (icon != NULL) {
data->framed_pixbuf = frame_pixbuf (icon, NULL, DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE);
@@ -1634,7 +1652,7 @@ set_app_icon_from_filename (EphyApplicationDialogData *data,
pixbuf = gdk_pixbuf_new_from_file_at_size (filename, DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE, NULL);
if (pixbuf != NULL) {
- data->framed_pixbuf = frame_pixbuf (pixbuf, &data->icon_rgba, DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE);
+ data->framed_pixbuf = frame_pixbuf (G_ICON (pixbuf), &data->icon_rgba, DEFAULT_ICON_SIZE, DEFAULT_ICON_SIZE);
g_assert (data->icon_v == NULL);
data->icon_v = g_icon_serialize (G_ICON (data->framed_pixbuf));
create_install_dialog_when_ready (data);