From 67c53e46f99aec91c6773f3e92a0cec1f8c9ada5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 11 Feb 2023 14:20:23 -0500 Subject: [PATCH] Add gtk_snapshot_append_scaled_texture This is the snapshot api corresponding to gsk_texture_scale_node_new. --- gtk/gtksnapshot.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gtk/gtksnapshot.h | 5 +++++ 2 files changed, 47 insertions(+) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 56edc74b9f..32686d264b 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -1918,6 +1918,10 @@ gtk_snapshot_append_cairo (GtkSnapshot *snapshot, * Creates a new render node drawing the @texture * into the given @bounds and appends it to the * current render node of @snapshot. + * + * If the texture needs to be scaled to fill @bounds, + * linear filtering is used. See [method@Gtk.Snapshot.append_scaled_texture] + * if you need other filtering, such as nearest-neighbour. */ void gtk_snapshot_append_texture (GtkSnapshot *snapshot, @@ -1939,6 +1943,44 @@ gtk_snapshot_append_texture (GtkSnapshot *snapshot, gtk_snapshot_append_node_internal (snapshot, node); } +/** + * gtk_snapshot_append_scaled_texture: + * @snapshot: a `GtkSnapshot` + * @texture: the texture to render + * @filter: the filter to use + * @bounds: the bounds for the new node + * + * Creates a new render node drawing the @texture + * into the given @bounds and appends it to the + * current render node of @snapshot. + * + * In contrast to [method@Gtk.Snapshot.append_texture], + * this function provides control about how the filter + * that is used when scaling. + * + * Since: 4.10 + */ +void +gtk_snapshot_append_scaled_texture (GtkSnapshot *snapshot, + GdkTexture *texture, + GskScalingFilter filter, + const graphene_rect_t *bounds) +{ + GskRenderNode *node; + graphene_rect_t real_bounds; + float scale_x, scale_y, dx, dy; + + g_return_if_fail (snapshot != NULL); + g_return_if_fail (GDK_IS_TEXTURE (texture)); + g_return_if_fail (bounds != NULL); + + gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy); + gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds); + node = gsk_texture_scale_node_new (texture, &real_bounds, filter); + + gtk_snapshot_append_node_internal (snapshot, node); +} + /** * gtk_snapshot_append_color: * @snapshot: a `GtkSnapshot` diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h index 38cc0271aa..66d0d879f1 100644 --- a/gtk/gtksnapshot.h +++ b/gtk/gtksnapshot.h @@ -152,6 +152,11 @@ GDK_AVAILABLE_IN_ALL void gtk_snapshot_append_texture (GtkSnapshot *snapshot, GdkTexture *texture, const graphene_rect_t *bounds); +GDK_AVAILABLE_IN_4_10 +void gtk_snapshot_append_scaled_texture (GtkSnapshot *snapshot, + GdkTexture *texture, + GskScalingFilter filter, + const graphene_rect_t *bounds); GDK_AVAILABLE_IN_ALL void gtk_snapshot_append_color (GtkSnapshot *snapshot, const GdkRGBA *color, -- 2.30.2