[gtk+/wip/otte/rendernode: 20/29] tests: Add a simple test to convert rendernode to png
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/rendernode: 20/29] tests: Add a simple test to convert rendernode to png
- Date: Thu, 22 Dec 2016 03:29:41 +0000 (UTC)
commit 52d426d08f24ff791d4c990a9915e55c9c9bc9f2
Author: Benjamin Otte <otte redhat com>
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;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]