rendernode: Respect clip when drawing scale nodes
authorBenjamin Otte <otte@redhat.com>
Mon, 13 Feb 2023 00:44:48 +0000 (01:44 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 3 Mar 2023 17:31:31 +0000 (11:31 -0600)
Scale nodes can use large scale factors and we don't want to create
insanely huge Cairo surfaces.

A subsequent commit will add the texture-scale-magnify-10000x
test which fails without this fix.

gsk/gskrendernodeimpl.c

index d0bd24b7247290d1d6b149b5ae43d5354a4a3055..5d1f19da5bff4c373742aa5cbdb9d9643d32a422 100644 (file)
@@ -1635,10 +1635,19 @@ gsk_texture_scale_node_draw (GskRenderNode *node,
   };
   cairo_t *cr2;
   cairo_surface_t *surface2;
+  graphene_rect_t clip_rect;
+
+  /* Make sure we draw the minimum region by using the clip */
+  gsk_cairo_rectangle (cr, &node->bounds);
+  cairo_clip (cr);
+  _graphene_rect_init_from_clip_extents (&clip_rect, cr);
+  if (clip_rect.size.width <= 0 || clip_rect.size.height <= 0)
+    return;
 
   surface2 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-                                         (int) ceilf (node->bounds.size.width),
-                                         (int) ceilf (node->bounds.size.height));
+                                         (int) ceilf (clip_rect.size.width),
+                                         (int) ceilf (clip_rect.size.height));
+  cairo_surface_set_device_offset (surface2, -clip_rect.origin.x, -clip_rect.origin.y);
   cr2 = cairo_create (surface2);
 
   surface = gdk_texture_download_surface (self->texture);