From 431f144f3795c8a7ec6177cda3b0d6f14bf0200f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 28 Sep 2020 11:23:51 -0400 Subject: [PATCH 1/2] gsk: Normalize when transforming bounds Bounds are assumed to be normalized, and transforms with negative scales or 3d rotations can make us get negative sizes. Fix by Benjamin Otte. --- gsk/gsktransform.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gsk/gsktransform.c b/gsk/gsktransform.c index 2bd1bdc920..7f9cc20e5b 100644 --- a/gsk/gsktransform.c +++ b/gsk/gsktransform.c @@ -1793,10 +1793,11 @@ gsk_transform_transform_bounds (GskTransform *self, float dx, dy; gsk_transform_to_translate (self, &dx, &dy); - out_rect->origin.x = rect->origin.x + dx; - out_rect->origin.y = rect->origin.y + dy; - out_rect->size.width = rect->size.width; - out_rect->size.height = rect->size.height; + graphene_rect_init (out_rect, + rect->origin.x + dx, + rect->origin.y + dy, + rect->size.width, + rect->size.height); } break; @@ -1806,10 +1807,11 @@ gsk_transform_transform_bounds (GskTransform *self, gsk_transform_to_affine (self, &scale_x, &scale_y, &dx, &dy); - out_rect->origin.x = (rect->origin.x * scale_x) + dx; - out_rect->origin.y = (rect->origin.y * scale_y) + dy; - out_rect->size.width = rect->size.width * scale_x; - out_rect->size.height = rect->size.height * scale_y; + graphene_rect_init (out_rect, + (rect->origin.x * scale_x) + dx, + (rect->origin.y * scale_y) + dy, + rect->size.width * scale_x, + rect->size.height * scale_y); } break; From b711c12bbe3f1917b6cc3986b972db40e9d7c390 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 27 Sep 2020 12:33:13 -0400 Subject: [PATCH 2/2] glarea: Flip our texture The texture that produce is upside-down, compared to what GSK expects, so flip things around with a transform. This fixes the shadertoy demo being upside-down after a recent fix to avoid downloading and reuploading the texture. --- gtk/gtkglarea.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c index 4cb815e1d9..3387a36ca2 100644 --- a/gtk/gtkglarea.c +++ b/gtk/gtkglarea.c @@ -744,11 +744,18 @@ gtk_gl_area_snapshot (GtkWidget *widget, texture->height, release_texture, texture); + /* Our texture is rendered by OpenGL, so it is upside down, + * compared to what GSK expects, so flip it back. + */ + gtk_snapshot_save (snapshot); + gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, gtk_widget_get_height (widget))); + gtk_snapshot_scale (snapshot, 1, -1); gtk_snapshot_append_texture (snapshot, texture->holder, &GRAPHENE_RECT_INIT (0, 0, gtk_widget_get_width (widget), gtk_widget_get_height (widget))); + gtk_snapshot_restore (snapshot); g_object_unref (texture->holder); }