x11: Initialize GL at startup

We need to initialize GL to select the Visual we are going to use for
all our Windows.

As the Visual needs to be known before we know if we are even gonna use
GL later, we can't avoid initializing it.

Note that this previously happened, too. It was just hidden behind the
GdkScreen initialization.
This commit is contained in:
Benjamin Otte 2021-06-06 17:07:05 +02:00
parent 8bfe82f686
commit 0fce30070f
3 changed files with 26 additions and 32 deletions

View File

@ -1335,6 +1335,25 @@ set_sm_client_id (GdkDisplay *display,
gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
}
static void
gdk_x11_display_init_gl (GdkX11Display *self)
{
GdkDisplay *display G_GNUC_UNUSED = GDK_DISPLAY (self);
if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE))
return;
if (!GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX))
{
/* We favour EGL */
if (gdk_x11_screen_init_egl (self->screen))
return;
}
if (gdk_x11_screen_init_glx (self->screen))
return;
}
/**
* gdk_x11_display_open:
* @display_name: (nullable): name of the X display.
@ -1406,6 +1425,7 @@ gdk_x11_display_open (const char *display_name)
* as we care about GLX details such as alpha/depth/stencil depth,
* stereo and double buffering
*/
gdk_x11_display_init_gl (display_x11);
gdk_x11_screen_update_visuals_for_glx (display_x11->screen);
if (display_x11->screen->rgba_visual)

View File

@ -54,27 +54,6 @@ gdk_x11_gl_context_init (GdkX11GLContext *self)
self->do_frame_sync = TRUE;
}
gboolean
gdk_x11_screen_init_gl (GdkX11Screen *screen)
{
GdkDisplay *display G_GNUC_UNUSED = GDK_SCREEN_DISPLAY (screen);
if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE))
return FALSE;
if (!GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX))
{
/* We favour EGL */
if (gdk_x11_screen_init_egl (screen))
return TRUE;
}
if (gdk_x11_screen_init_glx (screen))
return TRUE;
return FALSE;
}
GdkGLContext *
gdk_x11_surface_create_gl_context (GdkSurface *surface,
gboolean attached,
@ -86,8 +65,13 @@ gdk_x11_surface_create_gl_context (GdkSurface *surface,
GdkDisplay *display;
display = gdk_surface_get_display (surface);
display_x11 = GDK_X11_DISPLAY (display);
if (!gdk_x11_screen_init_gl (GDK_SURFACE_SCREEN (surface)))
if (display_x11->have_egl)
context = gdk_x11_gl_context_egl_new (surface, attached, share, error);
else if (display_x11->have_glx)
context = gdk_x11_gl_context_glx_new (surface, attached, share, error);
else
{
g_set_error_literal (error, GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
@ -95,14 +79,6 @@ gdk_x11_surface_create_gl_context (GdkSurface *surface,
return NULL;
}
display_x11 = GDK_X11_DISPLAY (display);
if (display_x11->have_egl)
context = gdk_x11_gl_context_egl_new (surface, attached, share, error);
else if (display_x11->have_glx)
context = gdk_x11_gl_context_glx_new (surface, attached, share, error);
else
g_assert_not_reached ();
if (context == NULL)
return NULL;

View File

@ -60,8 +60,6 @@ struct _GdkX11GLContextClass
void (* bind_for_frame_fence) (GdkX11GLContext *self);
};
gboolean gdk_x11_screen_init_gl (GdkX11Screen *screen);
GdkGLContext * gdk_x11_surface_create_gl_context (GdkSurface *window,
gboolean attached,
GdkGLContext *share,