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.
This commit is contained in:
Alexander Larsson 2017-03-17 16:12:45 +01:00
parent b843efcb79
commit 1fe4b13871
2 changed files with 56 additions and 29 deletions

View File

@ -760,24 +760,18 @@ gsk_renderer_get_profiler (GskRenderer *renderer)
}
static GType
get_renderer_for_env_var (GdkWindow *window)
get_renderer_for_name (const char *renderer_name)
{
static GType env_var_type = G_TYPE_NONE;
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;
return G_TYPE_INVALID;
else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0)
env_var_type = GSK_TYPE_CAIRO_RENDERER;
return 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;
return GSK_TYPE_GL_RENDERER;
#ifdef GDK_RENDERING_VULKAN
else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0)
env_var_type = GSK_TYPE_VULKAN_RENDERER;
return = GSK_TYPE_VULKAN_RENDERER;
#endif
else if (g_ascii_strcasecmp (renderer_name, "help") == 0)
{
@ -789,13 +783,34 @@ get_renderer_for_env_var (GdkWindow *window)
#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;
}
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)
{
static GType env_var_type = G_TYPE_NONE;
if (env_var_type == G_TYPE_NONE)
{
const char *renderer_name = g_getenv ("GSK_RENDERER");
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 },

View File

@ -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 ();