diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2023-02-09 12:32:47 +0100 |
---|---|---|
committer | Marge Bot <marge-bot@gnome.org> | 2023-02-22 12:21:36 +0000 |
commit | 60694c0d9b3e636273878adf4e37cdc8a566f153 (patch) | |
tree | bde7710cadfc6dfd69b3e78f0f2752ac70d74c39 | |
parent | f7429db961417ef278e8a16b61bcd3fd4e02b1b4 (diff) | |
download | epiphany-60694c0d9b3e636273878adf4e37cdc8a566f153.tar.gz |
Web view snapshot is now a GdkTexture instead of cairo_surface_t
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1281>
-rw-r--r-- | lib/ephy-snapshot-service.c | 25 | ||||
-rw-r--r-- | src/window-commands.c | 42 |
2 files changed, 17 insertions, 50 deletions
diff --git a/lib/ephy-snapshot-service.c b/lib/ephy-snapshot-service.c index 85b842b04..7c203687d 100644 --- a/lib/ephy-snapshot-service.c +++ b/lib/ephy-snapshot-service.c @@ -212,22 +212,21 @@ out: } static GdkPixbuf * -ephy_snapshot_service_prepare_snapshot (cairo_surface_t *surface) +ephy_snapshot_service_prepare_snapshot (GdkTexture *texture) { GdkPixbuf *snapshot, *scaled; int orig_width, orig_height; - orig_width = cairo_image_surface_get_width (surface); - orig_height = cairo_image_surface_get_height (surface); + orig_width = gdk_texture_get_width (texture); + orig_height = gdk_texture_get_height (texture); if (!orig_width || !orig_height) return NULL; + snapshot = gdk_pixbuf_get_from_texture (texture); + if (orig_width < EPHY_THUMBNAIL_WIDTH || orig_height < EPHY_THUMBNAIL_HEIGHT) { - snapshot = gdk_pixbuf_get_from_surface (surface, - 0, 0, - orig_width, orig_height); scaled = gdk_pixbuf_scale_simple (snapshot, EPHY_THUMBNAIL_WIDTH, EPHY_THUMBNAIL_HEIGHT, @@ -236,7 +235,6 @@ ephy_snapshot_service_prepare_snapshot (cairo_surface_t *surface) gfloat width_ratio = (gfloat)EPHY_THUMBNAIL_WIDTH / (gfloat)orig_width; gfloat new_height = orig_height * width_ratio; - snapshot = gdk_pixbuf_get_from_surface (surface, 0, 0, orig_width, orig_height); scaled = gdk_pixbuf_scale_simple (snapshot, EPHY_THUMBNAIL_WIDTH, new_height, @@ -393,12 +391,12 @@ snapshot_saved (EphySnapshotService *service, } static void -save_snapshot (cairo_surface_t *surface, - GTask *task) +save_snapshot (GdkTexture *texture, + GTask *task) { SnapshotAsyncData *data = g_task_get_task_data (task); - data->snapshot = ephy_snapshot_service_prepare_snapshot (surface); + data->snapshot = ephy_snapshot_service_prepare_snapshot (texture); if (!data->snapshot) { g_task_return_new_error (task, EPHY_SNAPSHOT_SERVICE_ERROR, @@ -421,18 +419,17 @@ on_snapshot_ready (WebKitWebView *web_view, GAsyncResult *result, GTask *task) { - cairo_surface_t *surface; + g_autoptr (GdkTexture) texture = NULL; GError *error = NULL; - surface = webkit_web_view_get_snapshot_finish (web_view, result, &error); + texture = webkit_web_view_get_snapshot_finish (web_view, result, &error); if (error) { g_task_return_error (task, error); g_object_unref (task); return; } - save_snapshot (surface, task); - cairo_surface_destroy (surface); + save_snapshot (texture, task); } static gboolean diff --git a/src/window-commands.c b/src/window-commands.c index 2e1f28346..97e612eb5 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -2028,55 +2028,25 @@ get_suggested_filename (EphyEmbed *embed) static void -save_snapshot (cairo_surface_t *surface, - const char *file) -{ - g_autoptr (GdkPixbuf) pixbuf = NULL; - g_autofree char *snapshot_path = NULL; - g_autoptr (GError) error = NULL; - int width; - int height; - gboolean ret; - - /* Create a pixbuf */ - width = cairo_image_surface_get_width (surface); - height = cairo_image_surface_get_height (surface); - - pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height); - if (!pixbuf) - return; - - ret = gdk_pixbuf_save (pixbuf, file, "png", &error, NULL); - if (!ret) { - g_warning ("Failed to save image to %s: %s", snapshot_path, error->message); - return; - } -} - -static void take_snapshot_full_cb (GObject *source, GAsyncResult *res, gpointer user_data) { - WebKitWebView *view = WEBKIT_WEB_VIEW (source); - GError *error = NULL; - cairo_surface_t *surface; - gchar *file = user_data; + g_autoptr (WebKitWebView) view = WEBKIT_WEB_VIEW (source); + g_autoptr (GError) error = NULL; + g_autoptr (GdkTexture) texture = NULL; + g_autofree char *file = user_data; if (!file) return; - surface = webkit_web_view_get_snapshot_finish (view, res, &error); + texture = webkit_web_view_get_snapshot_finish (view, res, &error); if (error) { g_warning ("Failed to take snapshot: %s", error->message); return; } - save_snapshot (surface, file); - cairo_surface_destroy (surface); - - g_free (file); - g_object_unref (view); + gdk_texture_save_to_png (texture, file); } void |