glx: Move error trap even further out
authorBenjamin Otte <otte@redhat.com>
Tue, 6 Jun 2023 02:57:12 +0000 (04:57 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 6 Jun 2023 03:20:34 +0000 (05:20 +0200)
This way we only create one error trap for all attempts to create a
context instead of up to 3.

gdk/x11/gdkglcontext-glx.c

index 07830897f80902b9717faf8b78bcf9e398fa43fc..4b0ff395beea1e70c6bc5fb29cebc599bb1a3aff 100644 (file)
@@ -543,8 +543,6 @@ gdk_x11_context_create_glx_context (GdkGLContext *context,
   if (share != NULL)
     share_glx = GDK_X11_GL_CONTEXT_GLX (share);
 
-  gdk_x11_display_error_trap_push (display);
-
   supported_versions = gdk_gl_versions_get_for_api (api);
   for (j = 0; gdk_gl_version_greater_equal (&supported_versions[j], &version); j++)
     {
@@ -572,8 +570,6 @@ gdk_x11_context_create_glx_context (GdkGLContext *context,
         break;
     }
 
-  gdk_x11_display_error_trap_pop_ignored (display);
-
   if (ctx == NULL)
     {
       GDK_DISPLAY_DEBUG (display, OPENGL, "Failed to create a GLX context");
@@ -660,25 +656,35 @@ gdk_x11_gl_context_glx_realize (GdkGLContext  *context,
   if (share != NULL && gdk_gl_context_is_legacy (share))
     legacy = TRUE;
 
+  gdk_x11_display_error_trap_push (display);
+
   if (preferred_api == GDK_GL_API_GL)
     {
-      if ((api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, legacy)) ||
-          (api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GLES, legacy)) ||
-          (api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, TRUE)))
-        return api;
+      api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, legacy);
+      if (api == 0)
+        api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GLES, legacy);
+      if (api == 0)
+        api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, TRUE);
     }
   else
     {
-      if ((api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GLES, FALSE)) ||
-          (api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, legacy)) ||
-          (api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, TRUE)))
-        return api;
+      api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GLES, FALSE);
+      if (api == 0)
+        api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, legacy);
+      if (api == 0)
+        api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, TRUE);
+    }
+
+  gdk_x11_display_error_trap_pop_ignored (display);
+
+  if (api == 0)
+    {
+      g_set_error_literal (error, GDK_GL_ERROR,
+                           GDK_GL_ERROR_NOT_AVAILABLE,
+                           _("Unable to create a GL context"));
     }
 
-  g_set_error_literal (error, GDK_GL_ERROR,
-                       GDK_GL_ERROR_NOT_AVAILABLE,
-                       _("Unable to create a GL context"));
-  return 0;
+  return api;
 }
 
 #undef N_GLX_ATTRS