Commit 55638416 authored by Benjamin Otte's avatar Benjamin Otte

gsk: Add gsk_renderer_new_for_window()

and remove gsk_renderer_get_for_display().

This new function returns a realized renderer. Because of that, GSK can
catch failures to realize, destroy the renderer and try another one.

Or in short: I can finally use GTK on Weston with the nvidia binary
drivers again.
Signed-off-by: default avatarEmmanuele Bassi <ebassi@gnome.org>
parent ce98df88
<SECTION> <SECTION>
<FILE>GskRenderer</FILE> <FILE>GskRenderer</FILE>
gsk_renderer_get_for_display gsk_renderer_new_for_window
gsk_renderer_set_viewport gsk_renderer_set_viewport
gsk_renderer_get_viewport gsk_renderer_get_viewport
gsk_renderer_set_scale_factor gsk_renderer_set_scale_factor
......
...@@ -686,23 +686,11 @@ gsk_renderer_get_profiler (GskRenderer *renderer) ...@@ -686,23 +686,11 @@ gsk_renderer_get_profiler (GskRenderer *renderer)
return priv->profiler; return priv->profiler;
} }
/** static GType
* gsk_renderer_get_for_display: get_renderer_for_env_var (GdkWindow *window)
* @display: a #GdkDisplay
*
* Creates an appropriate #GskRenderer instance for the given @display.
*
* Returns: (transfer full) (nullable): a #GskRenderer
*
* Since: 3.90
*/
GskRenderer *
gsk_renderer_get_for_display (GdkDisplay *display)
{ {
static const char *use_software; static const char *use_software;
GType renderer_type = G_TYPE_INVALID;
if (use_software == NULL) if (use_software == NULL)
{ {
use_software = g_getenv ("GSK_USE_SOFTWARE"); use_software = g_getenv ("GSK_USE_SOFTWARE");
...@@ -711,27 +699,87 @@ gsk_renderer_get_for_display (GdkDisplay *display) ...@@ -711,27 +699,87 @@ gsk_renderer_get_for_display (GdkDisplay *display)
} }
if (use_software[0] != '0') if (use_software[0] != '0')
return g_object_new (GSK_TYPE_CAIRO_RENDERER, "display", display, NULL); return GSK_TYPE_CAIRO_RENDERER;
return G_TYPE_INVALID;
}
static GType
get_renderer_for_backend (GdkWindow *window)
{
#ifdef GDK_WINDOWING_X11 #ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY (display)) if (GDK_IS_X11_WINDOW (window))
renderer_type = GSK_TYPE_GL_RENDERER; return GSK_TYPE_GL_RENDERER;
else
#endif #endif
#ifdef GDK_WINDOWING_WAYLAND #ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_DISPLAY (display)) if (GDK_IS_WAYLAND_WINDOW (window))
renderer_type = GSK_TYPE_GL_RENDERER; return GSK_TYPE_GL_RENDERER;
else
#endif #endif
renderer_type = GSK_TYPE_CAIRO_RENDERER;
GSK_NOTE (RENDERER, g_print ("Creating renderer of type '%s' for display '%s'\n", return G_TYPE_INVALID;
g_type_name (renderer_type), }
G_OBJECT_TYPE_NAME (display)));
static GType
get_renderer_fallback (GdkWindow *window)
{
return GSK_TYPE_CAIRO_RENDERER;
}
static struct {
GType (* get_renderer) (GdkWindow *window);
} renderer_possibilities[] = {
{ get_renderer_for_env_var },
{ get_renderer_for_backend },
{ get_renderer_fallback },
};
g_assert (renderer_type != G_TYPE_INVALID); /**
* gsk_renderer_new_for_window:
* @display: a #GdkDisplay
*
* Creates an appropriate #GskRenderer instance for the given @window.
*
* The renderer will be realized when it is returned.
*
* Returns: (transfer full) (nullable): a #GskRenderer
*
* Since: 3.90
*/
GskRenderer *
gsk_renderer_new_for_window (GdkWindow *window)
{
GType renderer_type;
GskRenderer *renderer;
guint i;
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
for (i = 0; i < G_N_ELEMENTS (renderer_possibilities); i++)
{
renderer_type = renderer_possibilities[i].get_renderer (window);
if (renderer_type == G_TYPE_INVALID)
continue;
renderer = g_object_new (renderer_type,
"display", gdk_window_get_display (window),
NULL);
if (gsk_renderer_realize (renderer, window))
{
GSK_NOTE (RENDERER, g_print ("Using renderer of type '%s' for display '%s'\n",
G_OBJECT_TYPE_NAME (renderer),
G_OBJECT_TYPE_NAME (window)));
return renderer;
}
GSK_NOTE (RENDERER, g_print ("Failed to realize renderer of type '%s' for window '%s'\n",
G_OBJECT_TYPE_NAME (renderer),
G_OBJECT_TYPE_NAME (window)));
g_object_unref (renderer);
}
return g_object_new (renderer_type, "display", display, NULL); g_assert_not_reached ();
return NULL;
} }
cairo_surface_t * cairo_surface_t *
......
...@@ -39,7 +39,7 @@ GDK_AVAILABLE_IN_3_90 ...@@ -39,7 +39,7 @@ GDK_AVAILABLE_IN_3_90
GType gsk_renderer_get_type (void) G_GNUC_CONST; GType gsk_renderer_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_90 GDK_AVAILABLE_IN_3_90
GskRenderer * gsk_renderer_get_for_display (GdkDisplay *display); GskRenderer * gsk_renderer_new_for_window (GdkWindow *window);
GDK_AVAILABLE_IN_3_90 GDK_AVAILABLE_IN_3_90
void gsk_renderer_set_viewport (GskRenderer *renderer, void gsk_renderer_set_viewport (GskRenderer *renderer,
......
...@@ -6886,12 +6886,6 @@ gtk_window_realize (GtkWidget *widget) ...@@ -6886,12 +6886,6 @@ gtk_window_realize (GtkWidget *widget)
_gtk_widget_get_allocation (widget, &allocation); _gtk_widget_get_allocation (widget, &allocation);
if (priv->renderer == NULL)
{
priv->renderer = gsk_renderer_get_for_display (gtk_widget_get_display (widget));
gsk_renderer_set_scale_factor (priv->renderer, gtk_widget_get_scale_factor (widget));
}
if (gtk_widget_get_parent_window (widget)) if (gtk_widget_get_parent_window (widget))
{ {
gdk_window = gdk_window_new_child (gtk_widget_get_parent_window (widget), gdk_window = gdk_window_new_child (gtk_widget_get_parent_window (widget),
...@@ -6910,7 +6904,8 @@ gtk_window_realize (GtkWidget *widget) ...@@ -6910,7 +6904,8 @@ gtk_window_realize (GtkWidget *widget)
popover_realize (popover->widget, popover, window); popover_realize (popover->widget, popover, window);
} }
gsk_renderer_realize (priv->renderer, gdk_window); priv->renderer = gsk_renderer_new_for_window (gdk_window);
gsk_renderer_set_scale_factor (priv->renderer, gtk_widget_get_scale_factor (widget));
return; return;
} }
...@@ -6994,6 +6989,12 @@ gtk_window_realize (GtkWidget *widget) ...@@ -6994,6 +6989,12 @@ gtk_window_realize (GtkWidget *widget)
gtk_widget_register_window (widget, gdk_window); gtk_widget_register_window (widget, gdk_window);
gtk_widget_set_realized (widget, TRUE); gtk_widget_set_realized (widget, TRUE);
if (priv->renderer == NULL)
{
priv->renderer = gsk_renderer_new_for_window (gdk_window);
gsk_renderer_set_scale_factor (priv->renderer, gtk_widget_get_scale_factor (widget));
}
if (priv->client_decorated && priv->type == GTK_WINDOW_TOPLEVEL) if (priv->client_decorated && priv->type == GTK_WINDOW_TOPLEVEL)
{ {
const gchar *cursor_names[8] = { const gchar *cursor_names[8] = {
...@@ -7106,9 +7107,6 @@ gtk_window_realize (GtkWidget *widget) ...@@ -7106,9 +7107,6 @@ gtk_window_realize (GtkWidget *widget)
} }
check_scale_changed (window); check_scale_changed (window);
/* Renderer */
gsk_renderer_realize (priv->renderer, gdk_window);
} }
static void static void
......
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