glx: omit loader_loader() for macOS
[mesa.git] / src / glx / glxext.c
index 5f23d3717a4282b40b3167f92337bc7ff6e187fe..34e86ae734d46d1f3904f63546c8ed4757877026 100644 (file)
@@ -50,6 +50,9 @@
 #include "glxextensions.h"
 
 #include "util/debug.h"
+#ifndef GLX_USE_APPLEGL
+#include "dri_common.h"
+#endif
 
 #include <X11/Xlib-xcb.h>
 #include <xcb/xcb.h>
@@ -69,7 +72,7 @@ _X_HIDDEN int __glXDebug = 0;
 /* Extension required boiler plate */
 
 static const char __glXExtensionName[] = GLX_EXTENSION_NAME;
-  static struct glx_display *glx_displays;
+static struct glx_display *glx_displays;
 
 static /* const */ char *error_list[] = {
    "GLXBadContext",
@@ -214,6 +217,8 @@ FreeScreenConfigs(struct glx_display * priv)
    screens = ScreenCount(priv->dpy);
    for (i = 0; i < screens; i++) {
       psc = priv->screens[i];
+      if (!psc)
+         continue;
       glx_screen_cleanup(psc);
 
 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
@@ -343,9 +348,12 @@ static GLint
 convert_from_x_visual_type(int visualType)
 {
    static const int glx_visual_types[] = {
-      GLX_STATIC_GRAY, GLX_GRAY_SCALE,
-      GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
-      GLX_TRUE_COLOR, GLX_DIRECT_COLOR
+      [StaticGray]  = GLX_STATIC_GRAY,
+      [GrayScale]   = GLX_GRAY_SCALE,
+      [StaticColor] = GLX_STATIC_COLOR,
+      [PseudoColor] = GLX_PSEUDO_COLOR,
+      [TrueColor]   = GLX_TRUE_COLOR,
+      [DirectColor] = GLX_DIRECT_COLOR,
    };
 
    if (visualType < ARRAY_SIZE(glx_visual_types))
@@ -364,7 +372,6 @@ __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
                                     Bool fbconfig_style_tags)
 {
    int i;
-   GLint renderType = 0;
 
    if (!tagged_only) {
       /* Copy in the first set of properties */
@@ -372,7 +379,7 @@ __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
 
       config->visualType = convert_from_x_visual_type(*bp++);
 
-      config->rgbMode = *bp++;
+      config->renderType = *bp++ ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
 
       config->redBits = *bp++;
       config->greenBits = *bp++;
@@ -402,8 +409,6 @@ __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
 #endif
    }
 
-   config->sRGBCapable = GL_FALSE;
-
    /*
     ** Additional properties may be in a list at the end
     ** of the reply.  They are in pairs of property type
@@ -418,7 +423,10 @@ __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
       
       switch (tag) {
       case GLX_RGBA:
-         FETCH_OR_SET(rgbMode);
+         if (fbconfig_style_tags)
+            config->renderType = *bp++ ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
+         else
+            config->renderType = GLX_RGBA_BIT;
          break;
       case GLX_BUFFER_SIZE:
          config->rgbBits = *bp++;
@@ -500,7 +508,7 @@ __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
 #endif
          break;
       case GLX_RENDER_TYPE: /* fbconfig render type bits */
-         renderType = *bp++;
+         config->renderType = *bp++;
          break;
       case GLX_X_RENDERABLE:
          config->xRenderable = *bp++;
@@ -593,26 +601,13 @@ __glXInitializeVisualConfigFromTags(struct glx_config * config, int count,
       }
    }
 
-   if (renderType != 0 && renderType != GLX_DONT_CARE) {
-      config->renderType = renderType;
-      config->floatMode = (renderType &
-         (GLX_RGBA_FLOAT_BIT_ARB|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT)) != 0;
-   } else {
-      /* If there wasn't GLX_RENDER_TYPE property, set it based on
-       * config->rgbMode.  The only way to communicate that the config is
-       * floating-point is via GLX_RENDER_TYPE, so this cannot be a float
-       * config.
-       */
-      config->renderType =
-         (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
-   }
-
    /* The GLX_ARB_fbconfig_float spec says:
     *
     *     "Note that floating point rendering is only supported for
     *     GLXPbuffer drawables."
     */
-   if (config->floatMode)
+   if (config->renderType &
+       (GLX_RGBA_FLOAT_BIT_ARB|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT))
       config->drawableType &= GLX_PBUFFER_BIT;
 }
 
@@ -660,6 +655,8 @@ createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
        */
       m->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
 #endif
+      /* Older X servers don't send this so we default it here. */
+      m->sRGBCapable = GL_FALSE;
        __glXInitializeVisualConfigFromTags(m, nprops, props,
                                           tagged_only, GL_TRUE);
       m->screen = screen;
@@ -720,7 +717,8 @@ static GLboolean
    LockDisplay(dpy);
 
    psc->configs = NULL;
-   if (atof(priv->serverGLXversion) >= 1.3) {
+   if (priv->majorVersion > 1 ||
+       (priv->majorVersion == 1 && priv->minorVersion >= 3)) {
       GetReq(GLXGetFBConfigs, fb_req);
       fb_req->reqType = priv->majorOpcode;
       fb_req->glxCode = X_GLXGetFBConfigs;
@@ -800,7 +798,7 @@ AllocAndFetchScreenConfigs(Display * dpy, struct glx_display * priv)
     ** First allocate memory for the array of per screen configs.
     */
    screens = ScreenCount(dpy);
-   priv->screens = malloc(screens * sizeof *priv->screens);
+   priv->screens = calloc(screens, sizeof *priv->screens);
    if (!priv->screens)
       return GL_FALSE;
 
@@ -902,7 +900,7 @@ __glXInitialize(Display * dpy)
    }
 
    XESetCloseDisplay(dpy, dpyPriv->codes->extension, __glXCloseDisplay);
-   XESetErrorString (dpy, dpyPriv->codes->extension,__glXErrorString);
+   XESetErrorString (dpy, dpyPriv->codes->extension, __glXErrorString);
 
    dpyPriv->glXDrawHash = __glxHashCreate();
 
@@ -912,6 +910,11 @@ __glXInitialize(Display * dpy)
 
    dpyPriv->drawHash = __glxHashCreate();
 
+#ifndef GLX_USE_APPLEGL
+   /* Set the logger before the *CreateDisplay functions. */
+   loader_set_logger(dri_message);
+#endif
+
    /*
     ** Initialize the direct rendering per display data and functions.
     ** Note: This _must_ be done before calling any other DRI routines