diff --git a/tools/gtk-rendernode-tool-render.c b/tools/gtk-rendernode-tool-render.c index c8d98da3f8..28d0c37fdf 100644 --- a/tools/gtk-rendernode-tool-render.c +++ b/tools/gtk-rendernode-tool-render.c @@ -143,14 +143,13 @@ render_file (const char *filename, { GdkTexture *texture; GskRenderer *renderer; - GdkSurface *window; - if (renderer_name) - g_object_set_data_full (G_OBJECT (gdk_display_get_default ()), "gsk-renderer", - g_strdup (renderer_name), g_free); - - window = gdk_surface_new_toplevel (gdk_display_get_default ()); - renderer = gsk_renderer_new_for_surface (window); + renderer = create_renderer (renderer_name, &error); + if (renderer == NULL) + { + g_printerr (_("Failed to create renderer: %s\n"), error->message); + exit (1); + } texture = gsk_renderer_render_texture (renderer, node, NULL); diff --git a/tools/gtk-rendernode-tool-utils.c b/tools/gtk-rendernode-tool-utils.c index e91cbc3ea2..deab3e36fc 100644 --- a/tools/gtk-rendernode-tool-utils.c +++ b/tools/gtk-rendernode-tool-utils.c @@ -29,6 +29,9 @@ #include #include "gtk-rendernode-tool.h" +#ifdef GDK_WINDOWING_BROADWAY +#include +#endif static void deserialize_error_func (const GskParseLocation *start, @@ -73,3 +76,62 @@ load_node_file (const char *filename) return gsk_render_node_deserialize (bytes, deserialize_error_func, NULL); } + +/* keep in sync with gsk/gskrenderer.c */ +static GskRenderer * +get_renderer_for_name (const char *renderer_name) +{ + if (renderer_name == NULL) + return NULL; +#ifdef GDK_WINDOWING_BROADWAY + else if (g_ascii_strcasecmp (renderer_name, "broadway") == 0) + return gsk_broadway_renderer_new (); +#endif + else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0) + return gsk_cairo_renderer_new (); + else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0 || + g_ascii_strcasecmp (renderer_name, "gl") == 0) + return gsk_gl_renderer_new (); + else if (g_ascii_strcasecmp (renderer_name, "ngl") == 0) + return gsk_ngl_renderer_new (); +#ifdef GDK_RENDERING_VULKAN + else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0) + return gsk_vulkan_renderer_new (); +#endif + else + return NULL; +} + +GskRenderer * +create_renderer (const char *name, GError **error) +{ + GskRenderer *renderer; + + if (name == NULL) + { + /* awwwwwkward - there should be code to get the + * default renderer without a surface */ + static GdkSurface *window = NULL; + + if (window == NULL) + window = gdk_surface_new_toplevel (gdk_display_get_default ()); + return gsk_renderer_new_for_surface (window); + } + + renderer = get_renderer_for_name (name); + + if (renderer == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "No renderer named \"%s\"", name); + return NULL; + } + + if (!gsk_renderer_realize_for_display (renderer, gdk_display_get_default (), error)) + { + g_object_unref (renderer); + return NULL; + } + + return renderer; +} diff --git a/tools/gtk-rendernode-tool.h b/tools/gtk-rendernode-tool.h index adece50e12..27410d7619 100644 --- a/tools/gtk-rendernode-tool.h +++ b/tools/gtk-rendernode-tool.h @@ -6,3 +6,4 @@ void do_render (int *argc, const char ***argv); void do_info (int *argc, const char ***argv); GskRenderNode *load_node_file (const char *filename); +GskRenderer *create_renderer (const char *name, GError **error);