testsuite: Fix gsk test
authorMatthias Clasen <mclasen@redhat.com>
Fri, 14 Apr 2023 07:22:01 +0000 (09:22 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 1 May 2023 17:43:33 +0000 (13:43 -0400)
The repeated tests were not careful enough to produce
the correct reference image to match what the repeat
node does.

With these changes, all cairo tests pass.

testsuite/gsk/compare-render.c
testsuite/gsk/compare/border-one-rounded.node [new file with mode: 0644]
testsuite/gsk/compare/border-one-rounded.png [new file with mode: 0644]

index 0746c98f9678eca83fbf67fbbbe071806f4d5b6a..4e97781cbe6b980eeca48c080aa701eb2498bbf0 100644 (file)
@@ -115,6 +115,20 @@ save_image (GdkTexture *texture,
   g_free (filename);
 }
 
+static void
+save_node (GskRenderNode *node,
+           const char    *test_name,
+           const char    *extension)
+{
+  char *filename = get_output_file (test_name, ".node", extension);
+  gboolean result;
+
+  g_print ("Storing modified nodes at %s\n", filename);
+  result = gsk_render_node_write_to_file (node, filename, NULL);
+  g_assert_true (result);
+  g_free (filename);
+}
+
 static void
 deserialize_error_func (const GskParseLocation *start,
                         const GskParseLocation *end,
@@ -278,6 +292,7 @@ main (int argc, char **argv)
 
       if (diff_texture)
         {
+          save_node (node2, node_file, "-flipped.node");
           save_image (diff_texture, node_file, "-flipped.diff.png");
           g_object_unref (diff_texture);
           success = FALSE;
@@ -291,36 +306,55 @@ main (int argc, char **argv)
   if (repeat)
     {
       GskRenderNode *node2;
-      GdkPixbuf *pixbuf, *pixbuf2;
+      GdkPixbuf *pixbuf, *pixbuf2, *pixbuf3;
       int width, height;
       graphene_rect_t node_bounds;
       graphene_rect_t bounds;
+      float offset_x, offset_y;
 
       gsk_render_node_get_bounds (node, &node_bounds);
+
+      if (node_bounds.size.width > 32768. || node_bounds.size.height > 32768.)
+        {
+          g_print ("Avoiding repeat test that exceeds cairo image surface dimensions");
+          exit (77);
+        }
+
       bounds.origin.x = 0.;
       bounds.origin.y = 0.;
       bounds.size.width = 2 * node_bounds.size.width;
       bounds.size.height = 2 * node_bounds.size.height;
 
+      offset_x = floorf (fmodf (node_bounds.origin.x, node_bounds.size.width));
+      offset_y = floorf (fmodf (node_bounds.origin.y, node_bounds.size.height));
+      if (offset_x < 0)
+        offset_x += node_bounds.size.width;
+      if (offset_y < 0)
+        offset_y += node_bounds.size.height;
+
       node2 = gsk_repeat_node_new (&bounds, node, &node_bounds);
       rendered_texture = gsk_renderer_render_texture (renderer, node2, NULL);
-
       save_image (rendered_texture, node_file, "-repeated.out.png");
 
       pixbuf = gdk_pixbuf_new_from_file (png_file, &error);
+
       width = gdk_pixbuf_get_width (pixbuf);
       height = gdk_pixbuf_get_height (pixbuf);
       pixbuf2 = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
                                 gdk_pixbuf_get_has_alpha (pixbuf),
                                 gdk_pixbuf_get_bits_per_sample (pixbuf),
-                                width * 2,
-                                height * 2);
-      gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, pixbuf2, 0, 0);
-      gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, pixbuf2, width, 0);
-      gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, pixbuf2, 0, height);
-      gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, pixbuf2, width, height);
+                                width * 3,
+                                height * 3);
 
-      reference_texture = gdk_texture_new_for_pixbuf (pixbuf2);
+      for (int i = 0; i < 3; i++)
+        for (int j = 0; j < 3; j++)
+          gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, pixbuf2, i * width,  j * height);
+
+      pixbuf3 = gdk_pixbuf_new_subpixbuf (pixbuf2, width - (int) offset_x, height - (int) offset_y, 2 * width, 2 * height);
+
+      reference_texture = gdk_texture_new_for_pixbuf (pixbuf3);
+
+      g_object_unref (pixbuf3);
       g_object_unref (pixbuf2);
       g_object_unref (pixbuf);
 
@@ -330,6 +364,7 @@ main (int argc, char **argv)
 
       if (diff_texture)
         {
+          save_node (node2, node_file, "-repeated.node");
           save_image (diff_texture, node_file, "-repeated.diff.png");
           g_object_unref (diff_texture);
           success = FALSE;
@@ -362,6 +397,7 @@ main (int argc, char **argv)
 
       if (diff_texture)
         {
+          save_node (node2, node_file, "-rotated.node");
           save_image (diff_texture, node_file, "-rotated.diff.png");
           g_object_unref (diff_texture);
           success = FALSE;
diff --git a/testsuite/gsk/compare/border-one-rounded.node b/testsuite/gsk/compare/border-one-rounded.node
new file mode 100644 (file)
index 0000000..53ad843
--- /dev/null
@@ -0,0 +1,23 @@
+border {
+  outline: 0 0 50 50 / 0 0 0 20;
+}
+color {
+  bounds: 0 29 4 11;
+  color: rgb(255,192,203);
+}
+color {
+  bounds: 2 40 4 4;
+  color: rgb(255,192,203);
+}
+color {
+  bounds: 4 42 4 4;
+  color: rgb(255,192,203);
+}
+color {
+  bounds: 6 44 4 4;
+  color: rgb(255,192,203);
+}
+color {
+  bounds: 9 46 11 4;
+  color: rgb(255,192,203);
+}
diff --git a/testsuite/gsk/compare/border-one-rounded.png b/testsuite/gsk/compare/border-one-rounded.png
new file mode 100644 (file)
index 0000000..fe75324
Binary files /dev/null and b/testsuite/gsk/compare/border-one-rounded.png differ