Add gtk_snapshot_append_scaled_texture
authorMatthias Clasen <mclasen@redhat.com>
Sat, 11 Feb 2023 19:20:23 +0000 (14:20 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 11 Feb 2023 20:09:38 +0000 (15:09 -0500)
This is the snapshot api corresponding to
gsk_texture_scale_node_new.

gtk/gtksnapshot.c
gtk/gtksnapshot.h

index 56edc74b9f70bc4e2ed56661c56d727dce059da8..32686d264b8580fc0b270a0be4a27208da9c0a2c 100644 (file)
@@ -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`
index 38cc0271aa4b61dc3b1c163c609bad2197b33e8f..66d0d879f15e2d90cb75c3413dfdc8dd4296018f 100644 (file)
@@ -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,