Commit 2faad03f authored by Benjamin Otte's avatar Benjamin Otte

gsk: Improve GSK_RENDERER env var handling

- Recognize "gl" as well as "opengl" for the GL renderer
- GSK_RENDERER=help now works
- g_warning() for an unrecognized renderer (typo detection!)
- g_print() the actual renderer that is used (and error messages when
  selecting) when a GSK_RENDERER is given, so you'll notice if your
  renderer isn't taken.
parent 3e9811d9
...@@ -725,14 +725,28 @@ get_renderer_for_env_var (GdkWindow *window) ...@@ -725,14 +725,28 @@ get_renderer_for_env_var (GdkWindow *window)
env_var_type = G_TYPE_INVALID; env_var_type = G_TYPE_INVALID;
else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0) else if (g_ascii_strcasecmp (renderer_name, "cairo") == 0)
env_var_type = GSK_TYPE_CAIRO_RENDERER; env_var_type = GSK_TYPE_CAIRO_RENDERER;
else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0) else if (g_ascii_strcasecmp (renderer_name, "opengl") == 0
|| g_ascii_strcasecmp (renderer_name, "gl") == 0)
env_var_type = GSK_TYPE_GL_RENDERER; env_var_type = GSK_TYPE_GL_RENDERER;
#ifdef GDK_WINDOWING_VULKAN #ifdef GDK_WINDOWING_VULKAN
else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0) else if (g_ascii_strcasecmp (renderer_name, "vulkan") == 0)
env_var_type = GSK_TYPE_VULKAN_RENDERER; env_var_type = GSK_TYPE_VULKAN_RENDERER;
#endif #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");
g_print (" vulkan - Use the Vulkan renderer (available if GTK is compiled with Vulkan support)\n");
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 else
env_var_type = G_TYPE_INVALID; {
g_warning ("Unrecognized renderer \"%s\". Try GSK_RENDERER=help", renderer_name);
env_var_type = G_TYPE_INVALID;
}
} }
return env_var_type; return env_var_type;
...@@ -760,11 +774,12 @@ get_renderer_fallback (GdkWindow *window) ...@@ -760,11 +774,12 @@ get_renderer_fallback (GdkWindow *window)
} }
static struct { static struct {
gboolean verbose;
GType (* get_renderer) (GdkWindow *window); GType (* get_renderer) (GdkWindow *window);
} renderer_possibilities[] = { } renderer_possibilities[] = {
{ get_renderer_for_env_var }, { TRUE, get_renderer_for_env_var },
{ get_renderer_for_backend }, { FALSE, get_renderer_for_backend },
{ get_renderer_fallback }, { FALSE, get_renderer_fallback },
}; };
/** /**
...@@ -785,6 +800,7 @@ gsk_renderer_new_for_window (GdkWindow *window) ...@@ -785,6 +800,7 @@ gsk_renderer_new_for_window (GdkWindow *window)
GType renderer_type; GType renderer_type;
GskRenderer *renderer; GskRenderer *renderer;
GError *error = NULL; GError *error = NULL;
gboolean verbose = FALSE;
guint i; guint i;
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
...@@ -795,22 +811,32 @@ gsk_renderer_new_for_window (GdkWindow *window) ...@@ -795,22 +811,32 @@ gsk_renderer_new_for_window (GdkWindow *window)
if (renderer_type == G_TYPE_INVALID) if (renderer_type == G_TYPE_INVALID)
continue; continue;
/* If a renderer is selected that's marked as verbose, start printing
* information to stdout.
*/
verbose |= renderer_possibilities[i].verbose;
renderer = g_object_new (renderer_type, renderer = g_object_new (renderer_type,
"display", gdk_window_get_display (window), "display", gdk_window_get_display (window),
NULL); NULL);
if (gsk_renderer_realize (renderer, window, &error)) if (gsk_renderer_realize (renderer, window, &error))
{ {
GSK_NOTE (RENDERER, g_print ("Using renderer of type '%s' for display '%s'\n", if (verbose || GSK_DEBUG_CHECK (RENDERER))
G_OBJECT_TYPE_NAME (renderer), {
G_OBJECT_TYPE_NAME (window))); g_print ("Using renderer of type '%s' for display '%s'\n",
G_OBJECT_TYPE_NAME (renderer),
G_OBJECT_TYPE_NAME (window));
}
return renderer; return renderer;
} }
GSK_NOTE (RENDERER, g_print ("Failed to realize renderer of type '%s' for window '%s': %s\n", if (verbose || GSK_DEBUG_CHECK (RENDERER))
G_OBJECT_TYPE_NAME (renderer), {
G_OBJECT_TYPE_NAME (window), g_print ("Failed to realize renderer of type '%s' for window '%s': %s\n",
error->message)); G_OBJECT_TYPE_NAME (renderer),
G_OBJECT_TYPE_NAME (window),
error->message);
}
g_object_unref (renderer); g_object_unref (renderer);
g_clear_error (&error); g_clear_error (&error);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment