Subject: [gtk+/wip/otte/rendernode: 20/29] tests: Add a
simple test to convert rendernode to png



commit 52d426d08f24ff791d4c990a9915e55c9c9bc9f2
Author: Benjamin Otte <otte@xxxxxxxxxx>
Date: Wed Dec 21 07:20:28 2016 +0100

tests: Add a simple test to convert rendernode to png

Takes a rendernode file, outputs a PNG. Nothing more.

tests/Makefile.am | 2 +
tests/rendernode.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 943329d..e6bff0a 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 0000000..70be90d
--- /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;
+}
_______________________________________________
commits-list mailing list (read only)
https://mail.gnome.org/mailman/listinfo/commits-list

Want to limit the commits to a few modules? Go to above URL, log in to edit
your options and select the modules ('topics') you want.



Programming list archiving by: Enterprise Git Hosting