mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +00:00
tests: Add a simple test to convert rendernode to png
Takes a rendernode file, outputs a PNG. Nothing more.
This commit is contained in:
parent
735846cc82
commit
b4ac7ffed4
@ -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)
|
||||
|
68
tests/rendernode.c
Normal file
68
tests/rendernode.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user