summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2016-12-21 07:20:28 +0100
committerBenjamin Otte <otte@redhat.com>2016-12-22 04:17:27 +0100
commit52d426d08f24ff791d4c990a9915e55c9c9bc9f2 (patch)
tree11f2d38c8ecb3d8fcd8c78a98e1aa6440c88775d
parent75510f7123a4fa479357ee7c138957e6fbb63bd0 (diff)
downloadgtk+-52d426d08f24ff791d4c990a9915e55c9c9bc9f2.tar.gz
tests: Add a simple test to convert rendernode to png
Takes a rendernode file, outputs a PNG. Nothing more.
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/rendernode.c68
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 943329d88c..e6bff0a459 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,6 +27,7 @@ fontconfig_programs = testfontchooserdialog
endif
noinst_PROGRAMS = $(TEST_PROGS) \
+ rendernode \
overlayscroll \
syncscroll \
animated-resizing \
@@ -161,6 +162,7 @@ if USE_X11
noinst_PROGRAMS += testerrors
endif
+rendernode_DEPENDENCIES = $(TEST_DEPS)
animated_resizing_DEPENDENCIES = $(TEST_DEPS)
animated_revealing_DEPENDENCIES = $(TEST_DEPS)
flicker_DEPENDENCIES = $(TEST_DEPS)
diff --git a/tests/rendernode.c b/tests/rendernode.c
new file mode 100644
index 0000000000..70be90db6a
--- /dev/null
+++ b/tests/rendernode.c
@@ -0,0 +1,68 @@
+#include <gtk/gtk.h>
+
+static GOptionEntry options[] = {
+ { NULL }
+};
+
+int
+main(int argc, char **argv)
+{
+ graphene_rect_t bounds;
+ cairo_surface_t *surface;
+ GskRenderNode *node;
+ cairo_t *cr;
+ GError *error = NULL;
+ GBytes *bytes;
+ char *contents;
+ gsize len;
+
+ if (!gtk_init_with_args (&argc, &argv, "NODE-FILE PNG-FILE",
+ options, NULL, &error))
+ {
+ g_printerr ("Option parsing failed: %s\n", error->message);
+ return 1;
+ }
+
+ if (argc != 3)
+ {
+ g_printerr ("Usage: %s [OPTIONS] NODE-FILE PNG-FILE\n", argv[0]);
+ return 1;
+ }
+
+ if (!g_file_get_contents (argv[1], &contents, &len, &error))
+ {
+ g_printerr ("Could not open node file: %s\n", error->message);
+ return 1;
+ }
+
+ bytes = g_bytes_new_take (contents, len);
+ node = gsk_render_node_deserialize (bytes);
+ g_bytes_unref (bytes);
+
+ if (node == NULL)
+ {
+ g_printerr ("Invalid node file.\n");
+ return 1;
+ }
+
+ gsk_render_node_get_bounds (node, &bounds);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, ceil (bounds.size.width), ceil (bounds.size.height));
+ cr = cairo_create (surface);
+
+ cairo_translate (cr, - bounds.origin.x, - bounds.origin.y);
+ gsk_render_node_draw (node, cr);
+
+ cairo_destroy (cr);
+ gsk_render_node_unref (node);
+
+ if (cairo_surface_write_to_png (surface, argv[2]))
+ {
+ cairo_surface_destroy (surface);
+ g_print ("Failed to save PNG file.\n");
+ return 1;
+ }
+
+ cairo_surface_destroy (surface);
+
+ return 0;
+}