Merge branch '7.8'
[mesa.git] / src / glx / glxcmds.c
index ef8674f4e0b1b75035f83646671ff726eb357fc2..be9d6f29c01e6770dcccfe08eca27d73d355b67e 100644 (file)
@@ -379,11 +379,11 @@ CreateContext(Display * dpy, int generic_id,
 {
    GLXContext gc;
 #ifdef GLX_DIRECT_RENDERING
-   __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
 #ifdef GLX_USE_APPLEGL
-   const __GLcontextModes *mode;
    int errorcode;
    bool x11error;
+#else
+   __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
 #endif
 #endif
     
@@ -481,17 +481,7 @@ CreateContext(Display * dpy, int generic_id,
 
    /* TODO: darwin: Integrate with above to do indirect */
 #ifdef GLX_USE_APPLEGL
-   mode = _gl_context_modes_find_fbconfig(psc->configs, 
-                                          fbconfig->fbconfigID);
-
-   if(NULL == mode) {
-      __glXSendError(dpy, BadValue, fbconfig->fbconfigID, X_GLXCreateContext,
-                     true);
-      __glXFreeContext(gc);
-      return NULL;
-   }
-   
-   if(apple_glx_create_context(&gc->driContext, dpy, screen, mode, 
+   if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig, 
                                shareList ? shareList->driContext : NULL,
                                &errorcode, &x11error)) {
       __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error);
@@ -500,7 +490,7 @@ CreateContext(Display * dpy, int generic_id,
    }
    
    gc->currentContextTag = -1;
-   gc->mode = mode;
+   gc->mode = fbconfig;
    gc->isDirect = allowDirect;
 #endif
 
@@ -514,7 +504,7 @@ glXCreateContext(Display * dpy, XVisualInfo * vis,
    const __GLcontextModes *mode = NULL;
    int renderType = 0;
 
-#ifdef GLX_DIRECT_RENDERING
+#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
    __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, vis->screen);
 
    mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
@@ -1230,6 +1220,13 @@ init_fbconfig_for_chooser(__GLcontextModes * config,
     }                                           \
   } while ( 0 )
 
+/* Test that all bits from a are contained in b */
+#define MATCH_MASK(param)                      \
+  do {                                         \
+    if ((a->param & ~b->param) != 0)           \
+      return False;                            \
+  } while (0);
+
 /**
  * Determine if two GLXFBConfigs are compatible.
  *
@@ -1268,11 +1265,8 @@ fbconfigs_compatible(const __GLcontextModes * const a,
    MATCH_DONT_CARE(stereoMode);
    MATCH_EXACT(level);
 
-   if (((a->drawableType & b->drawableType) == 0)
-       || ((a->renderType & b->renderType) == 0)) {
-      return False;
-   }
-
+   MATCH_MASK(drawableType);
+   MATCH_MASK(renderType);
 
    /* There is a bug in a few of the XFree86 DDX drivers.  They contain
     * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
@@ -2151,6 +2145,8 @@ __glXGetSwapIntervalMESA(void)
       }
    }
 #endif
+
+#ifdef GLX_DIRECT_RENDERING
    if (gc != NULL && gc->driContext) {
       __GLXscreenConfigs *psc;
 
@@ -2161,6 +2157,7 @@ __glXGetSwapIntervalMESA(void)
         return psc->driScreen->getSwapInterval(pdraw);
       }
    }
+#endif
 
    return 0;
 }
@@ -2277,7 +2274,9 @@ __glXGetVideoSyncSGI(unsigned int *count)
    int ret;
    GLXContext gc = __glXGetCurrentContext();
    __GLXscreenConfigs *psc;
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw;
+#endif
 
    if (!gc)
       return GLX_BAD_CONTEXT;
@@ -2288,7 +2287,9 @@ __glXGetVideoSyncSGI(unsigned int *count)
 #endif
 
    psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
+#ifdef GLX_DIRECT_RENDERING
    pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
+#endif
 
    /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
     * FIXME: there should be a GLX encoding for this call.  I can find no
@@ -2303,11 +2304,14 @@ __glXGetVideoSyncSGI(unsigned int *count)
       return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
    }
 #endif
+
+#ifdef GLX_DIRECT_RENDERING
    if (psc->driScreen && psc->driScreen->getDrawableMSC) {
       ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
       *count = (unsigned) msc;
       return (ret == True) ? 0 : GLX_BAD_CONTEXT;
    }
+#endif
 
    return GLX_BAD_CONTEXT;
 }
@@ -2317,7 +2321,9 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
 {
    GLXContext gc = __glXGetCurrentContext();
    __GLXscreenConfigs *psc;
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw;
+#endif
    int64_t ust, msc, sbc;
    int ret;
 
@@ -2333,7 +2339,9 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
 #endif
 
    psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
+#ifdef GLX_DIRECT_RENDERING
    pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
+#endif
 
 #ifdef __DRI_MEDIA_STREAM_COUNTER
    if (psc->msc != NULL && psc->driScreen ) {
@@ -2343,12 +2351,15 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
       return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
    }
 #endif
+
+#ifdef GLX_DIRECT_RENDERING
    if (psc->driScreen && psc->driScreen->waitForMSC) {
       ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
                                       &sbc);
       *count = (unsigned) msc;
       return (ret == True) ? 0 : GLX_BAD_CONTEXT;
    }
+#endif
 
    return GLX_BAD_CONTEXT;
 }
@@ -2515,13 +2526,17 @@ __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
 {
    __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
    int i, ret;
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw;
+#endif
    __GLXscreenConfigs *psc;
 
    if (!priv)
       return False;
 
+#ifdef GLX_DIRECT_RENDERING
    pdraw = GetGLXDRIDrawable(dpy, drawable, &i);
+#endif
    psc = &priv->screenConfigs[i];
 
 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
@@ -2531,10 +2546,13 @@ __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
               && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0)
               && (__glXGetUST(ust) == 0) );
 #endif
+
+#ifdef GLX_DIRECT_RENDERING
    if (pdraw && psc && psc->driScreen && psc->driScreen->getDrawableMSC) {
       ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
       return ret;
    }
+#endif
 
    return False;
 }
@@ -2652,14 +2670,16 @@ __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
 {
    GLXContext gc = __glXGetCurrentContext();
    int screen;
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
+#endif
    __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
 
-   if (!pdraw || !gc) /* no GLX for this */
+   if (!gc) /* no GLX for this */
       return -1;
 
 #ifdef GLX_DIRECT_RENDERING
-   if (!gc->driContext)
+   if (!pdraw || !gc->driContext)
       return -1;
 #endif
 
@@ -2673,6 +2693,9 @@ __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
    if (divisor > 0 && remainder >= divisor)
       return -1;
 
+   if (target_msc == 0 && divisor == 0 && remainder == 0)
+      remainder = 1;
+
 #ifdef __DRI_SWAP_BUFFER_COUNTER
    if (psc->counters != NULL)
       return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc,
@@ -2696,7 +2719,9 @@ __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
                    int64_t * msc, int64_t * sbc)
 {
    int screen;
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
+#endif
    __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
    int ret;
 
@@ -2720,11 +2745,14 @@ __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
       return ((ret == 0) && (__glXGetUST(ust) == 0));
    }
 #endif
+
+#ifdef GLX_DIRECT_RENDERING
    if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
       ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
                                       ust, msc, sbc);
       return ret;
    }
+#endif
 
    return False;
 }
@@ -2736,7 +2764,9 @@ __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
                    int64_t * msc, int64_t * sbc)
 {
    int screen;
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
+#endif
    __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
    int ret;
 
@@ -2756,10 +2786,14 @@ __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
       return ((ret == 0) && (__glXGetUST(ust) == 0));
    }
 #endif
+
+#ifdef GLX_DIRECT_RENDERING
    if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
       ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
       return ret;
    }
+#endif
+
    return False;
 }