glx: Implement GLX_EXT_no_config_context
authorAdam Jackson <ajax@redhat.com>
Tue, 14 Nov 2017 20:13:06 +0000 (15:13 -0500)
committerAdam Jackson <ajax@redhat.com>
Tue, 24 Sep 2019 00:39:01 +0000 (20:39 -0400)
This is the GLX counterpart to EGL_KHR_no_config_context. Contexts may
now be created without reference to an fbconfig, in which case it is
treated as compatible with any fbconfig (and thus any GLX drawable).

Khronos: https://github.com/KhronosGroup/OpenGL-Registry/pull/102
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
12 files changed:
src/glx/applegl_glx.c
src/glx/create_context.c
src/glx/dri2_glx.c
src/glx/dri3_glx.c
src/glx/dri_common.c
src/glx/drisw_glx.c
src/glx/driwindows_glx.c
src/glx/g_glxglvnddispatchfuncs.c
src/glx/glxcmds.c
src/glx/glxextensions.c
src/glx/glxextensions.h
src/glx/tests/create_context_unittest.cpp

index c086e51..85f7005 100644 (file)
@@ -134,6 +134,9 @@ applegl_create_context(struct glx_screen *psc,
    /* TODO: Integrate this with apple_glx_create_context and make
     * struct apple_glx_context inherit from struct glx_context. */
 
+   if (!config)
+      return NULL;
+
    gc = calloc(1, sizeof(*gc));
    if (gc == NULL)
       return NULL;
index 38e949a..fa15d55 100644 (file)
 #error This code requires sizeof(uint32_t) == sizeof(int).
 #endif
 
+/* debian stretch still has ancient headers and we're apparently still
+ * using that for gitlab ci. please delete me when that's fixed.
+ */
+#ifndef X_GLXCreateContextAttribsARB
+#warning Please update your GLX protocol headers
+#define X_GLXCreateContextAttribsARB 34
+#endif
+
 _X_HIDDEN GLXContext
 glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
                           GLXContext share_context, Bool direct,
@@ -47,21 +55,11 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
    xcb_generic_error_t *err;
    xcb_void_cookie_t cookie;
    unsigned dummy_err = 0;
+   int screen = -1;
 
-
-   if (dpy == NULL || cfg == NULL)
-      return NULL;
-
-   /* This means that either the caller passed the wrong display pointer or
-    * one of the internal GLX data structures (probably the fbconfig) has an
-    * error.  There is nothing sensible to do, so return an error.
-    */
-   psc = GetGLXScreenConfigs(dpy, cfg->screen);
-   if (psc == NULL)
+   if (dpy == NULL)
       return NULL;
 
-   assert(cfg->screen == psc->scr);
-
    /* Count the number of attributes specified by the application.  All
     * attributes appear in pairs, except the terminating None.
     */
@@ -70,6 +68,29 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
         /* empty */ ;
    }
 
+   if (cfg) {
+      screen = cfg->screen;
+   } else {
+      for (unsigned int i = 0; i < num_attribs; i++) {
+         if (attrib_list[i * 2] == GLX_SCREEN)
+            screen = attrib_list[i * 2 + 1];
+      }
+      if (screen == -1) {
+         __glXSendError(dpy, BadValue, 0, X_GLXCreateContextAttribsARB, True);
+         return NULL;
+      }
+   }
+
+   /* This means that either the caller passed the wrong display pointer or
+    * one of the internal GLX data structures (probably the fbconfig) has an
+    * error.  There is nothing sensible to do, so return an error.
+    */
+   psc = GetGLXScreenConfigs(dpy, screen);
+   if (psc == NULL)
+      return NULL;
+
+   assert(screen == psc->scr);
+
    if (direct && psc->vtable->create_context_attribs) {
       /* GLX drops the error returned by the driver.  The expectation is that
        * an error will also be returned by the server.  The server's error
@@ -104,8 +125,8 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
    cookie =
       xcb_glx_create_context_attribs_arb_checked(c,
                                                 gc->xid,
-                                                cfg->fbconfigID,
-                                                cfg->screen,
+                                                cfg ? cfg->fbconfigID : 0,
+                                                screen,
                                                 gc->share_xid,
                                                 gc->isDirect,
                                                 num_attribs,
index bed25bb..f4a4a6c 100644 (file)
@@ -1135,6 +1135,7 @@ dri2BindExtensions(struct dri2_screen *psc, struct glx_display * priv,
 
       __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context");
       __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_profile");
+      __glXEnableDirectExtension(&psc->base, "GLX_EXT_no_config_context");
 
       if ((mask & ((1 << __DRI_API_GLES) |
                    (1 << __DRI_API_GLES2) |
index a5cf0e3..805172b 100644 (file)
@@ -750,6 +750,7 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv,
 
    __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context");
    __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_profile");
+   __glXEnableDirectExtension(&psc->base, "GLX_EXT_no_config_context");
 
    if ((mask & ((1 << __DRI_API_GLES) |
                 (1 << __DRI_API_GLES2) |
index a5fae27..d70bff4 100644 (file)
@@ -500,6 +500,10 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             return false;
          }
          break;
+      case GLX_SCREEN:
+         /* Implies GLX_EXT_no_config_context */
+         *render_type = GLX_DONT_CARE;
+         break;
       default:
         /* If an unknown attribute is received, fail.
          */
index f38dbbc..f5544f8 100644 (file)
@@ -789,6 +789,7 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
    if (psc->swrast->base.version >= 3) {
       __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context");
       __glXEnableDirectExtension(&psc->base, "GLX_ARB_create_context_profile");
+      __glXEnableDirectExtension(&psc->base, "GLX_EXT_no_config_context");
 
       /* DRISW version >= 2 implies support for OpenGL ES.
        */
index 8552543..b2dc810 100644 (file)
@@ -240,7 +240,7 @@ driwindows_create_context_attribs(struct glx_screen *base,
      identical values, so far
    */
 
-   if (!psc->base.driScreen)
+   if (!psc->base.driScreen || !config_base)
       return NULL;
 
    /* Check the renderType value */
index 0f02ed2..78c097f 100644 (file)
@@ -160,7 +160,19 @@ static GLXContext dispatch_CreateContextAttribsARB(Display *dpy,
     __GLXvendorInfo *dd;
     GLXContext ret;
 
-    dd = GetDispatchFromFBConfig(dpy, config);
+    if (config) {
+       dd = GetDispatchFromFBConfig(dpy, config);
+    } else if (attrib_list) {
+       int i, screen;
+
+       for (i = 0; attrib_list[i * 2] != None; i++) {
+          if (attrib_list[i * 2] == GLX_SCREEN) {
+             screen = attrib_list[i * 2 + 1];
+             dd = GetDispatchFromDrawable(dpy, RootWindow(dpy, screen));
+             break;
+          }
+       }
+    }
     if (dd == NULL)
         return None;
 
index 8927976..85041ad 100644 (file)
@@ -238,7 +238,7 @@ validate_renderType_against_config(const struct glx_config *config,
 {
    /* GLX_EXT_no_config_context supports any render type */
    if (!config)
-      return True;
+      return renderType == GLX_DONT_CARE;
 
    switch (renderType) {
       case GLX_RGBA_TYPE:
@@ -269,6 +269,9 @@ glx_context_init(struct glx_context *gc,
    gc->isDirect = GL_TRUE;
    gc->currentContextTag = -1;
 
+   if (!config)
+      gc->renderType = GLX_DONT_CARE;
+
    return True;
 }
 
index f6a7a31..ada1793 100644 (file)
@@ -147,6 +147,7 @@ static const struct extension_info known_glx_extensions[] = {
    { GLX(EXT_fbconfig_packed_float),   VER(0,0), Y, Y, N, N },
    { GLX(EXT_framebuffer_sRGB),        VER(0,0), Y, Y, N, N },
    { GLX(EXT_import_context),          VER(0,0), Y, Y, N, N },
+   { GLX(EXT_no_config_context),       VER(0,0), Y, N, N, N },
    { GLX(EXT_texture_from_pixmap),     VER(0,0), Y, N, N, N },
    { GLX(EXT_visual_info),             VER(0,0), Y, Y, N, N },
    { GLX(EXT_visual_rating),           VER(0,0), Y, Y, N, N },
index bbdb00d..4406b7c 100644 (file)
@@ -51,6 +51,7 @@ enum
    EXT_fbconfig_packed_float_bit,
    EXT_framebuffer_sRGB_bit,
    EXT_import_context_bit,
+   EXT_no_config_context_bit,
    EXT_texture_from_pixmap_bit,
    EXT_visual_info_bit,
    EXT_visual_rating_bit,
index a259058..d19271b 100644 (file)
@@ -172,15 +172,6 @@ TEST_F(glXCreateContextAttribARB_test, NULL_display_returns_None)
    EXPECT_EQ(0, fake_glx_context::contexts_allocated);
 }
 
-TEST_F(glXCreateContextAttribARB_test, NULL_fbconfig_returns_None)
-{
-   GLXContext ctx =
-      glXCreateContextAttribsARB(this->dpy, NULL, 0, False, NULL);
-
-   EXPECT_EQ(None, ctx);
-   EXPECT_EQ(0, fake_glx_context::contexts_allocated);
-}
-
 TEST_F(glXCreateContextAttribARB_test, NULL_screen_returns_None)
 {
    delete psc;