forked from AuroraMiddleware/gtk
tests: Improve rendernode test further
- Print benchmark output in fallback path - Always run rendering, even when no filename given - Don't require a filename when running with --benchmark
This commit is contained in:
parent
a36e5ceea7
commit
b97e4e8631
@ -29,7 +29,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 3 && (argc != 2 && dump_variant))
|
if (argc != 3 && (argc != 2 && (dump_variant || benchmark)))
|
||||||
{
|
{
|
||||||
g_printerr ("Usage: %s [OPTIONS] NODE-FILE PNG-FILE\n", argv[0]);
|
g_printerr ("Usage: %s [OPTIONS] NODE-FILE PNG-FILE\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
@ -68,59 +68,67 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fallback)
|
||||||
|
{
|
||||||
|
graphene_rect_t bounds;
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
|
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);
|
||||||
|
start = g_get_monotonic_time ();
|
||||||
|
gsk_render_node_draw (node, cr);
|
||||||
|
end = g_get_monotonic_time ();
|
||||||
|
if (benchmark)
|
||||||
|
g_print ("Rendered fallback in %.4gs\n", (double) (end - start) / G_USEC_PER_SEC);
|
||||||
|
|
||||||
|
cairo_destroy (cr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GskRenderer *renderer;
|
||||||
|
GdkWindow *window;
|
||||||
|
GskTexture *texture;
|
||||||
|
|
||||||
|
window = gdk_window_new_toplevel (gdk_display_get_default(), 0, 10 , 10);
|
||||||
|
renderer = gsk_renderer_new_for_window (window);
|
||||||
|
|
||||||
|
start = g_get_monotonic_time ();
|
||||||
|
texture = gsk_renderer_render_texture (renderer, node, NULL);
|
||||||
|
end = g_get_monotonic_time ();
|
||||||
|
if (benchmark)
|
||||||
|
g_print ("Rendered using %s in %.4gs\n", G_OBJECT_TYPE_NAME (renderer), (double) (end - start) / G_USEC_PER_SEC);
|
||||||
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
||||||
|
gsk_texture_get_width (texture),
|
||||||
|
gsk_texture_get_height (texture));
|
||||||
|
gsk_texture_download (texture,
|
||||||
|
cairo_image_surface_get_data (surface),
|
||||||
|
cairo_image_surface_get_stride (surface));
|
||||||
|
cairo_surface_mark_dirty (surface);
|
||||||
|
gsk_texture_unref (texture);
|
||||||
|
g_object_unref (window);
|
||||||
|
g_object_unref (renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
gsk_render_node_unref (node);
|
||||||
|
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
{
|
{
|
||||||
if (fallback)
|
cairo_status_t status;
|
||||||
{
|
|
||||||
graphene_rect_t bounds;
|
status = cairo_surface_write_to_png (surface, argv[2]);
|
||||||
cairo_t *cr;
|
|
||||||
|
|
||||||
gsk_render_node_get_bounds (node, &bounds);
|
if (status != CAIRO_STATUS_SUCCESS)
|
||||||
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);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GskRenderer *renderer;
|
|
||||||
GdkWindow *window;
|
|
||||||
GskTexture *texture;
|
|
||||||
|
|
||||||
window = gdk_window_new_toplevel (gdk_display_get_default(), 0, 10 , 10);
|
|
||||||
renderer = gsk_renderer_new_for_window (window);
|
|
||||||
|
|
||||||
start = g_get_monotonic_time ();
|
|
||||||
texture = gsk_renderer_render_texture (renderer, node, NULL);
|
|
||||||
end = g_get_monotonic_time ();
|
|
||||||
if (benchmark)
|
|
||||||
g_print ("Rendered using %s in %.4gs\n", G_OBJECT_TYPE_NAME (renderer), (double) (end - start) / G_USEC_PER_SEC);
|
|
||||||
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
||||||
gsk_texture_get_width (texture),
|
|
||||||
gsk_texture_get_height (texture));
|
|
||||||
gsk_texture_download (texture,
|
|
||||||
cairo_image_surface_get_data (surface),
|
|
||||||
cairo_image_surface_get_stride (surface));
|
|
||||||
cairo_surface_mark_dirty (surface);
|
|
||||||
gsk_texture_unref (texture);
|
|
||||||
g_object_unref (window);
|
|
||||||
g_object_unref (renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
gsk_render_node_unref (node);
|
|
||||||
|
|
||||||
if (cairo_surface_write_to_png (surface, argv[2]))
|
|
||||||
{
|
{
|
||||||
cairo_surface_destroy (surface);
|
cairo_surface_destroy (surface);
|
||||||
g_print ("Failed to save PNG file.\n");
|
g_print ("Failed to save PNG file: %s\n", cairo_status_to_string (status));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_destroy (surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cairo_surface_destroy (surface);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user