From ed31da3730a58fa74b6e8fea42ec57dbbdc5aff2 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 6 Mar 2024 22:31:06 +0100 Subject: [PATCH] Update "snapshot: linear-gradients cannot be affine-transformed" This is a better fix for commit 7ed6c39862206bd578642ae6037863e3598df029. The linear-gradient-nonorthogonal-linear-gradient test tests this. Related: !6692 --- gtk/gtksnapshot.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index b9e90431cc..34bc8a798d 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -2427,7 +2427,7 @@ gtk_snapshot_append_linear_gradient (GtkSnapshot *snapshot, { GskRenderNode *node; graphene_rect_t real_bounds; - float dx, dy; + float scale_x, scale_y, dx, dy; const GdkRGBA *first_color; gboolean need_gradient = FALSE; @@ -2437,8 +2437,11 @@ gtk_snapshot_append_linear_gradient (GtkSnapshot *snapshot, g_return_if_fail (stops != NULL); g_return_if_fail (n_stops > 1); - gtk_snapshot_ensure_translate (snapshot, &dx, &dy); - graphene_rect_offset_r (bounds, dx, dy, &real_bounds); + gtk_snapshot_ensure_affine_with_flags (snapshot, + ENSURE_POSITIVE_SCALE | ENSURE_UNIFORM_SCALE, + &scale_x, &scale_y, + &dx, &dy); + gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds); first_color = &stops[0].color; for (gsize i = 0; i < n_stops; i ++) @@ -2454,10 +2457,10 @@ gtk_snapshot_append_linear_gradient (GtkSnapshot *snapshot, { graphene_point_t real_start_point, real_end_point; - real_start_point.x = start_point->x + dx; - real_start_point.y = start_point->y + dy; - real_end_point.x = end_point->x + dx; - real_end_point.y = end_point->y + dy; + real_start_point.x = scale_x * start_point->x + dx; + real_start_point.y = scale_y * start_point->y + dy; + real_end_point.x = scale_x * end_point->x + dx; + real_end_point.y = scale_y * end_point->y + dy; node = gsk_linear_gradient_node_new (&real_bounds, &real_start_point, @@ -2494,7 +2497,7 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot *snapshot, { GskRenderNode *node; graphene_rect_t real_bounds; - float dx, dy; + float scale_x, scale_y, dx, dy; gboolean need_gradient = FALSE; const GdkRGBA *first_color; @@ -2504,8 +2507,8 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot *snapshot, g_return_if_fail (stops != NULL); g_return_if_fail (n_stops > 1); - gtk_snapshot_ensure_translate (snapshot, &dx, &dy); - graphene_rect_offset_r (bounds, dx, dy, &real_bounds); + 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); first_color = &stops[0].color; for (gsize i = 0; i < n_stops; i ++) @@ -2521,10 +2524,10 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot *snapshot, { graphene_point_t real_start_point, real_end_point; - real_start_point.x = start_point->x + dx; - real_start_point.y = start_point->y + dy; - real_end_point.x = end_point->x + dx; - real_end_point.y = end_point->y + dy; + real_start_point.x = scale_x * start_point->x + dx; + real_start_point.y = scale_y * start_point->y + dy; + real_end_point.x = scale_x * end_point->x + dx; + real_end_point.y = scale_y * end_point->y + dy; node = gsk_repeating_linear_gradient_node_new (&real_bounds, &real_start_point,