From 1fe4b1387113ffcd38e1c72a65120ade7ab0955e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 17 Mar 2017 16:12:45 +0100 Subject: [PATCH] Allow custom renderer for the inspector If you set GTK_INSPECTOR_RENDERER to the same type of values that GSK_RENDERER takes this can change the renderer used for the inspector. This is useful if you're debugging one renderer and don't want to affect the inspector. --- gsk/gskrenderer.c | 74 +++++++++++++++++++++++++----------------- gtk/inspector/window.c | 11 +++++++ 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c index bba01532c9..3c93e77939 100644 --- a/gsk/gskrenderer.c +++ b/gsk/gskrenderer.c @@ -759,6 +759,49 @@ gsk_renderer_get_profiler (GskRenderer *renderer) return priv->profiler; } +static GType +get_renderer_for_name (const char *renderer_name) +{ + if (renderer_name == NULL) + return G_TYPE_INVALID; + else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0) + return GSK_TYPE_CAIRO_RENDERER; + else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0 + || g_ascii_strcasecmp (renderer_name, "gl") == 0) + return GSK_TYPE_GL_RENDERER; +#ifdef GDK_RENDERING_VULKAN + else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0) + return = GSK_TYPE_VULKAN_RENDERER; +#endif + else if (g_ascii_strcasecmp (renderer_name, "help") == 0) + { + g_print ("Supported arguments for GSK_RENDERER environment variable:\n"); + g_print (" cairo - Use the Cairo fallback renderer\n"); + g_print (" opengl - Use the default OpenGL renderer\n"); +#ifdef GDK_RENDERING_VULKAN + g_print (" vulkan - Use the Vulkan renderer\n"); +#endif + g_print (" help - Print this help\n\n"); + g_print ("Other arguments will cause a warning and be ignored.\n"); + } + else + { + g_warning ("Unrecognized renderer \"%s\". Try GSK_RENDERER=help", renderer_name); + } + + return G_TYPE_INVALID; +} + +static GType +get_renderer_for_display (GdkWindow *window) +{ + GdkDisplay *display = gdk_window_get_display (window); + const char *renderer_name; + + renderer_name = g_object_get_data (display, "gsk-renderer"); + return get_renderer_for_name (renderer_name); +} + static GType get_renderer_for_env_var (GdkWindow *window) { @@ -767,35 +810,7 @@ get_renderer_for_env_var (GdkWindow *window) if (env_var_type == G_TYPE_NONE) { const char *renderer_name = g_getenv ("GSK_RENDERER"); - - if (renderer_name == NULL) - env_var_type = G_TYPE_INVALID; - else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0) - env_var_type = GSK_TYPE_CAIRO_RENDERER; - else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0 - || g_ascii_strcasecmp (renderer_name, "gl") == 0) - env_var_type = GSK_TYPE_GL_RENDERER; -#ifdef GDK_RENDERING_VULKAN - else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0) - env_var_type = GSK_TYPE_VULKAN_RENDERER; -#endif - else if (g_ascii_strcasecmp (renderer_name, "help") == 0) - { - g_print ("Supported arguments for GSK_RENDERER environment variable:\n"); - g_print (" cairo - Use the Cairo fallback renderer\n"); - g_print (" opengl - Use the default OpenGL renderer\n"); -#ifdef GDK_RENDERING_VULKAN - g_print (" vulkan - Use the Vulkan renderer\n"); -#endif - g_print (" help - Print this help\n\n"); - g_print ("Other arguments will cause a warning and be ignored.\n"); - env_var_type = G_TYPE_INVALID; - } - else - { - g_warning ("Unrecognized renderer \"%s\". Try GSK_RENDERER=help", renderer_name); - env_var_type = G_TYPE_INVALID; - } + env_var_type = get_renderer_for_name (renderer_name); } return env_var_type; @@ -826,6 +841,7 @@ static struct { gboolean verbose; GType (* get_renderer) (GdkWindow *window); } renderer_possibilities[] = { + { TRUE, get_renderer_for_display }, { TRUE, get_renderer_for_env_var }, { FALSE, get_renderer_for_backend }, { FALSE, get_renderer_fallback }, diff --git a/gtk/inspector/window.c b/gtk/inspector/window.c index beb44f9025..8134d50852 100644 --- a/gtk/inspector/window.c +++ b/gtk/inspector/window.c @@ -313,6 +313,17 @@ get_inspector_screen (void) g_message ("Failed to separate connection to default display"); } + + if (display) + { + const gchar *name; + + name = g_getenv ("GTK_INSPECTOR_RENDERER"); + + g_object_set_data_full (G_OBJECT (display), "gsk-renderer", + g_strdup (name), g_free); + } + if (!display) display = gdk_display_get_default ();