[gtk/wip/otte/glcontext: 3/3] gl: Checlk allowed APIs in realize()




commit 71b084e0565e673eec19d1ddd8c357ced88a5464
Author: Benjamin Otte <otte redhat com>
Date:   Thu Oct 7 22:10:39 2021 +0200

    gl: Checlk allowed APIs in realize()
    
    Add gdk_gl_context_is_api_allowed() for backends and make them use it.
    
    Finally, have them return the final API as the return value (or 0 on
    error).
    
    And then use that api instead of a use_es boolean flag.
    
    Fixes #4221

 gdk/gdk.c                          |   2 +-
 gdk/gdkglcontext.c                 | 130 ++++++++++++++++++++++---------------
 gdk/gdkglcontextprivate.h          |   5 +-
 gdk/macos/gdkmacosglcontext.c      |  13 ++--
 gdk/win32/gdkglcontext-win32-wgl.c |  14 ++--
 gdk/x11/gdkglcontext-glx.c         |  14 ++--
 6 files changed, 102 insertions(+), 76 deletions(-)
---
diff --git a/gdk/gdk.c b/gdk/gdk.c
index 123b0413ef..d40c5ee4df 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -121,7 +121,7 @@ static const GdkDebugKey gdk_debug_keys[] = {
   { "gl-software",     GDK_DEBUG_GL_SOFTWARE, "Force OpenGL software rendering" },
   { "gl-texture-rect", GDK_DEBUG_GL_TEXTURE_RECT, "Use OpenGL texture rectangle extension" },
   { "gl-legacy",       GDK_DEBUG_GL_LEGACY, "Use a legacy OpenGL context" },
-  { "gl-gles",         GDK_DEBUG_GL_GLES, "Use a GLES OpenGL context" },
+  { "gl-gles",         GDK_DEBUG_GL_GLES, "Only allow OpenGL GLES API" },
   { "gl-debug",        GDK_DEBUG_GL_DEBUG, "Insert debugging information in OpenGL" },
   { "gl-egl",          GDK_DEBUG_GL_EGL, "Use EGL on X11 or Windows" },
   { "gl-glx",          GDK_DEBUG_GL_GLX, "Use GLX on X11" },
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 138f774d3a..d52c044202 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -101,7 +101,6 @@ typedef struct {
   int minor;
   int gl_version;
 
-  guint realized : 1;
   guint has_khr_debug : 1;
   guint use_khr_debug : 1;
   guint has_unpack_subimage : 1;
@@ -112,7 +111,7 @@ typedef struct {
   guint is_legacy : 1;
 
   GdkGLAPI allowed_apis;
-  int use_es;
+  GdkGLAPI api;
 
   int max_debug_label_length;
 
@@ -264,7 +263,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
 
   if (!gdk_memory_format_gl_format (data_format,
-                                    priv->use_es,
+                                    gdk_gl_context_get_use_es (context),
                                     &gl_internalformat,
                                     &gl_format,
                                     &gl_type))
@@ -278,7 +277,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
       data = copy;
       data_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
       if (!gdk_memory_format_gl_format (data_format,
-                                        priv->use_es,
+                                        gdk_gl_context_get_use_es (context),
                                         &gl_internalformat,
                                         &gl_format,
                                         &gl_type))
@@ -303,8 +302,8 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
       glTexImage2D (texture_target, 0, gl_internalformat, width, height, 0, gl_format, gl_type, data);
       glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
     }
-  else if ((!priv->use_es ||
-            (priv->use_es && (priv->gl_version >= 30 || priv->has_unpack_subimage))))
+  else if ((!gdk_gl_context_get_use_es (context) ||
+            (priv->gl_version >= 30 || priv->has_unpack_subimage)))
     {
       glPixelStorei (GL_UNPACK_ROW_LENGTH, stride / bpp);
 
@@ -325,7 +324,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
 
 #define N_EGL_ATTRS     16
 
-static gboolean
+static GdkGLAPI
 gdk_gl_context_real_realize (GdkGLContext  *context,
                              GError       **error)
 {
@@ -342,7 +341,8 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
       EGLContext ctx;
       EGLint context_attribs[N_EGL_ATTRS];
       int major, minor, flags;
-      gboolean debug_bit, forward_bit, legacy_bit, use_es;
+      gboolean debug_bit, forward_bit, legacy_bit;
+      GdkGLAPI api;
       int i = 0;
       G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
 
@@ -351,8 +351,6 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
       forward_bit = gdk_gl_context_get_forward_compatible (context);
       legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ||
                    (share != NULL && gdk_gl_context_is_legacy (share));
-      use_es = GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES) ||
-               (share != NULL && gdk_gl_context_get_use_es (share));
 
       if (display->have_egl_no_config_context)
         egl_config = NULL;
@@ -366,7 +364,8 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
       if (forward_bit)
         flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
 
-      if (!use_es && eglBindAPI (EGL_OPENGL_API))
+      if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) &&
+          eglBindAPI (EGL_OPENGL_API))
         {
           /* We want a core profile, unless in legacy mode */
           context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
@@ -379,20 +378,23 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           context_attribs[i++] = legacy_bit ? 3 : major;
           context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
           context_attribs[i++] = legacy_bit ? 0 : minor;
+          api = GDK_GL_API_GL;
         }
-      else if (eglBindAPI (EGL_OPENGL_ES_API))
+      else if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) &&
+               eglBindAPI (EGL_OPENGL_ES_API))
         {
           context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
           if (major == 3)
             context_attribs[i++] = 3;
           else
             context_attribs[i++] = 2;
+          api = GDK_GL_API_GLES;
         }
       else
         {
           g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
-                               _("The EGL implementation supports neither OpenGL nor GLES"));
-          return FALSE;
+                               _("The EGL implementation does not support any allowed APIs"));
+          return 0;
         }
 
       /* Specify the flags */
@@ -408,7 +410,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
                                    debug_bit ? "yes" : "no",
                                    forward_bit ? "yes" : "no",
                                    legacy_bit ? "yes" : "no",
-                                   use_es ? "yes" : "no"));
+                                   api == GDK_GL_API_GLES ? "yes" : "no"));
 
       ctx = eglCreateContext (egl_display,
                               egl_config,
@@ -417,7 +419,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
                               context_attribs);
 
       /* If context creation failed without the ES bit, let's try again with it */
-      if (ctx == NULL && eglBindAPI (EGL_OPENGL_ES_API))
+      if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) && eglBindAPI 
(EGL_OPENGL_ES_API))
         {
           i = 0;
           context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
@@ -430,7 +432,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           g_assert (i < N_EGL_ATTRS);
 
           legacy_bit = FALSE;
-          use_es = TRUE;
+          api = GDK_GL_API_GLES;
 
           GDK_DISPLAY_NOTE (display, OPENGL,
                     g_message ("eglCreateContext failed, switching to OpenGLĀ ES"));
@@ -442,7 +444,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
         }
 
       /* If context creation failed without the legacy bit, let's try again with it */
-      if (ctx == NULL && eglBindAPI (EGL_OPENGL_API))
+      if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) && eglBindAPI 
(EGL_OPENGL_API))
         {
           i = 0;
           context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
@@ -457,7 +459,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           g_assert (i < N_EGL_ATTRS);
 
           legacy_bit = TRUE;
-          use_es = FALSE;
+          api = GDK_GL_API_GL;
 
           GDK_DISPLAY_NOTE (display, OPENGL,
                     g_message ("eglCreateContext failed, switching to legacy"));
@@ -473,7 +475,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
           g_set_error_literal (error, GDK_GL_ERROR,
                                GDK_GL_ERROR_NOT_AVAILABLE,
                                _("Unable to create a GL context"));
-          return FALSE;
+          return 0;
         }
 
       GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Created EGL context[%p]", ctx));
@@ -481,17 +483,16 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
       priv->egl_context = ctx;
 
       gdk_gl_context_set_is_legacy (context, legacy_bit);
-      gdk_gl_context_set_use_es (context, use_es);
 
       gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
 
-      return TRUE;
+      return api;
     }
 #endif
 
   g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
                        _("The current backend does not support OpenGL"));
-  return FALSE;
+  return 0;
 }
 
 #undef N_EGL_ATTRS
@@ -879,6 +880,14 @@ gdk_gl_context_has_unpack_subimage (GdkGLContext *context)
   return priv->has_unpack_subimage;
 }
 
+static gboolean
+gdk_gl_context_is_realized (GdkGLContext *context)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
+
+  return priv->api != 0;
+}
+
 /**
  * gdk_gl_context_set_debug_enabled:
  * @context: a `GdkGLContext`
@@ -899,7 +908,7 @@ gdk_gl_context_set_debug_enabled (GdkGLContext *context,
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
-  g_return_if_fail (!priv->realized);
+  g_return_if_fail (gdk_gl_context_is_realized (context));
 
   enabled = !!enabled;
 
@@ -948,7 +957,7 @@ gdk_gl_context_set_forward_compatible (GdkGLContext *context,
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
-  g_return_if_fail (!priv->realized);
+  g_return_if_fail (gdk_gl_context_is_realized (context));
 
   compatible = !!compatible;
 
@@ -1001,7 +1010,7 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
 #endif
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
-  g_return_if_fail (!priv->realized);
+  g_return_if_fail (gdk_gl_context_is_realized (context));
 
   /* this will take care of the default */
   if (major == 0 && minor == 0)
@@ -1020,7 +1029,7 @@ gdk_gl_context_set_required_version (GdkGLContext *context,
   /* Enforce a minimum context version number of 3.2 for desktop GL,
    * and 2.0 for GLES
    */
-  if (priv->use_es > 0 || force_gles)
+  if (gdk_gl_context_get_use_es (context) || force_gles)
     min_ver = 200;
   else
     min_ver = 302;
@@ -1068,7 +1077,7 @@ gdk_gl_context_get_required_version (GdkGLContext *context,
    * enforce a context version number of 3.2 for desktop GL,
    * and 2.0 for GLES
    */
-  if (priv->use_es > 0 || force_gles)
+  if (gdk_gl_context_get_use_es (context) || force_gles)
     {
       default_major = 2;
       default_minor = 0;
@@ -1124,7 +1133,7 @@ gdk_gl_context_is_legacy (GdkGLContext *context)
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
-  g_return_val_if_fail (priv->realized, FALSE);
+  g_return_val_if_fail (gdk_gl_context_is_realized (context), FALSE);
 
   return priv->is_legacy;
 }
@@ -1164,13 +1173,11 @@ gboolean
 gdk_gl_context_is_shared (GdkGLContext *self,
                           GdkGLContext *other)
 {
-  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
-  GdkGLContextPrivate *priv_other = gdk_gl_context_get_instance_private (other);
-
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), FALSE);
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (other), FALSE);
 
-  if (!priv->realized || !priv_other->realized)
+  if (!gdk_gl_context_is_realized (self) ||
+      !gdk_gl_context_is_realized (other))
     return FALSE;
 
   return GDK_GL_CONTEXT_GET_CLASS (self)->is_shared (self, other);
@@ -1227,6 +1234,32 @@ gdk_gl_context_get_allowed_apis (GdkGLContext *self)
   return priv->allowed_apis;
 }
 
+gboolean
+gdk_gl_context_is_api_allowed (GdkGLContext  *self,
+                               GdkGLAPI       api,
+                               GError       **error)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
+
+  if (GDK_DISPLAY_DEBUG_CHECK (gdk_gl_context_get_display (self), GL_GLES))
+    {
+      if (!(api & GDK_GL_API_GLES))
+        {
+          g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
+                               _("Anything but OpenGL ES disabled via GDK_DEBUG"));
+        }
+    }
+
+  if (priv->allowed_apis & api)
+    return TRUE;
+
+  g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
+               _("Application does not support %s API"),
+               api == GDK_GL_API_GL ? "OpenGL" : "OpenGL ES");
+
+  return FALSE;
+}
+
 /**
  * gdk_gl_context_set_use_es:
  * @context: a `GdkGLContext`
@@ -1246,17 +1279,13 @@ gdk_gl_context_get_allowed_apis (GdkGLContext *self)
  * You should check the return value of [method@Gdk.GLContext.get_use_es]
  * after calling [method@Gdk.GLContext.realize] to decide whether to use
  * the OpenGL or OpenGL ES API, extensions, or shaders.
- *
- * Deprecated: 4.6: Use gdk_gl_context_set_allowed_apis() instead.
  */
 void
 gdk_gl_context_set_use_es (GdkGLContext *context,
                            int           use_es)
 {
-  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
-
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
-  g_return_if_fail (!priv->realized);
+  g_return_if_fail (gdk_gl_context_is_realized (context));
 
   switch (use_es)
   {
@@ -1290,10 +1319,7 @@ gdk_gl_context_get_use_es (GdkGLContext *context)
 
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
 
-  if (!priv->realized)
-    return FALSE;
-
-  return priv->use_es > 0;
+  return priv->api == GDK_GL_API_GLES;
 }
 
 static void APIENTRY
@@ -1406,12 +1432,12 @@ gdk_gl_context_realize (GdkGLContext  *context,
 
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
 
-  if (priv->realized)
+  if (priv->api)
     return TRUE;
 
-  priv->realized = GDK_GL_CONTEXT_GET_CLASS (context)->realize (context, error);
+  priv->api = GDK_GL_CONTEXT_GET_CLASS (context)->realize (context, error);
 
-  return priv->realized;
+  return priv->api;
 }
 
 static void
@@ -1423,7 +1449,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
   GdkDisplay *display;
 #endif
 
-  if (!priv->realized)
+  if (!gdk_gl_context_is_realized (context))
     return;
 
   if (priv->extensions_checked)
@@ -1431,9 +1457,6 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
 
   priv->gl_version = epoxy_gl_version ();
 
-  if (priv->use_es < 0)
-    priv->use_es = !epoxy_is_desktop_gl ();
-
   priv->has_debug_output = epoxy_has_gl_extension ("GL_ARB_debug_output") ||
                            epoxy_has_gl_extension ("GL_KHR_debug");
 
@@ -1454,7 +1477,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
       glDebugMessageCallback (gl_debug_message_callback, NULL);
     }
 
-  if (priv->use_es)
+  if (gdk_gl_context_get_use_es (context))
     {
       priv->has_unpack_subimage = epoxy_has_gl_extension ("GL_EXT_unpack_subimage");
       priv->has_khr_debug = epoxy_has_gl_extension ("GL_KHR_debug");
@@ -1481,7 +1504,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
                        "* Extensions checked:\n"
                        " - GL_KHR_debug: %s\n"
                        " - GL_EXT_unpack_subimage: %s",
-                       priv->use_es ? "OpenGL ES" : "OpenGL",
+                       gdk_gl_context_get_use_es (context) ? "OpenGL ES" : "OpenGL",
                        priv->gl_version / 10, priv->gl_version % 10,
                        priv->is_legacy ? "legacy" : "core",
                        glGetString (GL_SHADING_LANGUAGE_VERSION),
@@ -1500,7 +1523,6 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
 void
 gdk_gl_context_make_current (GdkGLContext *context)
 {
-  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
   MaskedContext *current, *masked_context;
   gboolean surfaceless;
 
@@ -1514,7 +1536,7 @@ gdk_gl_context_make_current (GdkGLContext *context)
     return;
 
   /* we need to realize the GdkGLContext if it wasn't explicitly realized */
-  if (!priv->realized)
+  if (!gdk_gl_context_is_realized (context))
     {
       GError *error = NULL;
 
@@ -1610,7 +1632,7 @@ gdk_gl_context_get_version (GdkGLContext *context,
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
-  g_return_if_fail (priv->realized);
+  g_return_if_fail (gdk_gl_context_is_realized (context));
 
   if (major != NULL)
     *major = priv->gl_version / 10;
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index add799d381..1879488b4f 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -62,7 +62,7 @@ struct _GdkGLContextClass
 
   GdkGLBackend        backend_type;
 
-  gboolean              (* realize)                             (GdkGLContext          *context,
+  GdkGLAPI              (* realize)                             (GdkGLContext          *context,
                                                                  GError               **error);
 
   gboolean              (* make_current)                        (GdkGLContext          *context,
@@ -102,6 +102,9 @@ void                    gdk_gl_backend_use                      (GdkGLBackend
 
 GdkGLContext *          gdk_gl_context_new_for_surface          (GdkSurface      *surface);
 
+gboolean                gdk_gl_context_is_api_allowed           (GdkGLContext    *self,
+                                                                 GdkGLAPI         api,
+                                                                 GError         **error);
 void                    gdk_gl_context_set_is_legacy            (GdkGLContext    *context,
                                                                  gboolean         is_legacy);
 
diff --git a/gdk/macos/gdkmacosglcontext.c b/gdk/macos/gdkmacosglcontext.c
index 313be91fb9..ca4b7545e9 100644
--- a/gdk/macos/gdkmacosglcontext.c
+++ b/gdk/macos/gdkmacosglcontext.c
@@ -184,7 +184,10 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
   g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
 
   if (self->gl_context != nil)
-    return TRUE;
+    return GDK_GL_API_GL;
+
+  if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, error))
+    return 0;
 
   existing = [NSOpenGLContext currentContext];
 
@@ -197,7 +200,7 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
   if (shared != NULL)
     {
       if (!(shared_gl_context = get_ns_open_gl_context (GDK_MACOS_GL_CONTEXT (shared), error)))
-        return FALSE;
+        return 0;
     }
 
   GDK_DISPLAY_NOTE (display,
@@ -206,7 +209,7 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
                                major, minor));
 
   if (!(pixelFormat = create_pixel_format (major, minor, error)))
-    return FALSE;
+    return 0;
 
   gl_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
                                           shareContext:shared_gl_context];
@@ -219,7 +222,7 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
                            GDK_GL_ERROR,
                            GDK_GL_ERROR_NOT_AVAILABLE,
                            "Failed to create NSOpenGLContext");
-      return FALSE;
+      return 0;
     }
 
   cgl_context = [gl_context CGLContextObj];
@@ -258,7 +261,7 @@ gdk_macos_gl_context_real_realize (GdkGLContext  *context,
   if (existing != NULL)
     [existing makeCurrentContext];
 
-  return TRUE;
+  return GDK_GL_API_GL;
 }
 
 static gboolean
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index ea5f377966..0edc40c55a 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -543,7 +543,7 @@ set_wgl_pixformat_for_hdc (HDC              hdc,
   return TRUE;
 }
 
-static gboolean
+static GdkGLAPI
 gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
                                   GError **error)
 {
@@ -564,6 +564,9 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
   GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
   GdkGLContext *share = gdk_display_get_gl_context (display);
 
+  if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, error))
+    return 0;
+
   gdk_gl_context_get_required_version (context, &major, &minor);
   debug_bit = gdk_gl_context_get_debug_enabled (context);
   compat_bit = gdk_gl_context_get_forward_compatible (context);
@@ -589,7 +592,7 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
                            GDK_GL_ERROR_UNSUPPORTED_FORMAT,
                            _("No available configurations for the given pixel format"));
 
-      return FALSE;
+      return 0;
     }
 
   /* if there isn't wglCreateContextAttribsARB() on WGL, use a legacy context */
@@ -622,7 +625,7 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
       g_set_error_literal (error, GDK_GL_ERROR,
                            GDK_GL_ERROR_NOT_AVAILABLE,
                            _("Unable to create a GL context"));
-      return FALSE;
+      return 0;
     }
 
   GDK_NOTE (OPENGL,
@@ -632,13 +635,10 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
 
   context_wgl->wgl_context = hglrc;
 
-  /* No GLES, WGL does not support using EGL contexts */
-  gdk_gl_context_set_use_es (context, FALSE);
-
   /* Ensure that any other context is created with a legacy bit set */
   gdk_gl_context_set_is_legacy (context, legacy_bit);
 
-  return TRUE;
+  return GDK_GL_API_GL;
 }
 
 static gboolean
diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c
index c9667fbeed..ccbcfcb337 100644
--- a/gdk/x11/gdkglcontext-glx.c
+++ b/gdk/x11/gdkglcontext-glx.c
@@ -509,7 +509,7 @@ on_surface_state_changed (GdkGLContext *context)
 }
 #endif
 
-static gboolean
+static GdkGLAPI
 gdk_x11_gl_context_glx_realize (GdkGLContext  *context,
                                 GError       **error)
 {
@@ -536,8 +536,9 @@ gdk_x11_gl_context_glx_realize (GdkGLContext  *context,
   /* If there is no glXCreateContextAttribsARB() then we default to legacy */
   legacy_bit = !display_x11->has_glx_create_context || GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY);
 
-  es_bit = (GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES) || (share != NULL && gdk_gl_context_get_use_es 
(share))) &&
-           (display_x11->has_glx_create_context && display_x11->has_glx_create_es2_context);
+  es_bit = gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL);
+  if (!es_bit && !gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, error))
+    return 0;
 
   /* We cannot share legacy contexts with core profile ones, so the
    * shared context is the one that decides if we're going to create
@@ -610,15 +611,12 @@ gdk_x11_gl_context_glx_realize (GdkGLContext  *context,
       g_set_error_literal (error, GDK_GL_ERROR,
                            GDK_GL_ERROR_NOT_AVAILABLE,
                            _("Unable to create a GL context"));
-      return FALSE;
+      return 0;
     }
 
   /* Ensure that any other context is created with a legacy bit set */
   gdk_gl_context_set_is_legacy (context, legacy_bit);
 
-  /* Ensure that any other context is created with an ES bit set */
-  gdk_gl_context_set_use_es (context, es_bit);
-
   GDK_DISPLAY_NOTE (display, OPENGL,
             g_message ("Realized GLX context[%p], %s, version: %d.%d",
                        context_glx->glx_context,
@@ -655,7 +653,7 @@ gdk_x11_gl_context_glx_realize (GdkGLContext  *context,
     }
 #endif
 
-  return TRUE;
+  return es_bit ? GDK_GL_API_GLES : GDK_GL_API_GL;
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]