Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / drivers / dri / common / dri_util.c
index a16cb504c73d28165fbc91f6b65398fe33f3f1aa..e112720471879f97c93551a995b017969a6c8604 100644 (file)
@@ -59,7 +59,7 @@ __driUtilMessage(const char *f, ...)
     va_list args;
 
     if (getenv("LIBGL_DEBUG")) {
-        fprintf(stderr, "libGL error: \n");
+        fprintf(stderr, "libGL");
         va_start(args, f);
         vfprintf(stderr, f, args);
         va_end(args);
@@ -163,21 +163,18 @@ static int driBindContext(__DRIcontext *pcp,
 {
     __DRIscreenPrivate *psp = pcp->driScreenPriv;
 
-    /*
-    ** Assume error checking is done properly in glXMakeCurrent before
-    ** calling driBindContext.
-    */
-
-    if (pcp == NULL || pdp == None || prp == None)
-       return GL_FALSE;
-
     /* Bind the drawable to the context */
-    pcp->driDrawablePriv = pdp;
-    pcp->driReadablePriv = prp;
-    pdp->driContextPriv = pcp;
-    pdp->refcount++;
-    if ( pdp != prp ) {
-       prp->refcount++;
+
+    if (pcp) {
+       pcp->driDrawablePriv = pdp;
+       pcp->driReadablePriv = prp;
+       if (pdp) {
+           pdp->driContextPriv = pcp;
+           pdp->refcount++;
+       }
+       if ( prp && pdp != prp ) {
+           prp->refcount++;
+       }
     }
 
     /*
@@ -186,23 +183,21 @@ static int driBindContext(__DRIcontext *pcp,
     */
 
     if (!psp->dri2.enabled) {
-       if (!pdp->pStamp || *pdp->pStamp != pdp->lastStamp) {
+       if (pdp && !pdp->pStamp) {
            DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
            __driUtilUpdateDrawableInfo(pdp);
            DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
        }
-       
-       if ((pdp != prp) && (!prp->pStamp || *prp->pStamp != prp->lastStamp)) {
+       if (prp && pdp != prp && !prp->pStamp) {
            DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
            __driUtilUpdateDrawableInfo(prp);
            DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID);
-       }
+        }
     }
 
     /* Call device-specific MakeCurrent */
-    (*psp->DriverAPI.MakeCurrent)(pcp, pdp, prp);
 
-    return GL_TRUE;
+    return (*psp->DriverAPI.MakeCurrent)(pcp, pdp, prp);
 }
 
 /*@}*/
@@ -314,10 +309,28 @@ static void driReportDamage(__DRIdrawable *pdp,
 static void driSwapBuffers(__DRIdrawable *dPriv)
 {
     __DRIscreen *psp = dPriv->driScreenPriv;
+    drm_clip_rect_t *rects;
+    int i;
 
     psp->DriverAPI.SwapBuffers(dPriv);
 
-    driReportDamage(dPriv, dPriv->pClipRects, dPriv->numClipRects);
+    if (!dPriv->numClipRects)
+        return;
+
+    rects = _mesa_malloc(sizeof(*rects) * dPriv->numClipRects);
+
+    if (!rects)
+        return;
+
+    for (i = 0; i < dPriv->numClipRects; i++) {
+        rects[i].x1 = dPriv->pClipRects[i].x1 - dPriv->x;
+        rects[i].y1 = dPriv->pClipRects[i].y1 - dPriv->y;
+        rects[i].x2 = dPriv->pClipRects[i].x2 - dPriv->x;
+        rects[i].y2 = dPriv->pClipRects[i].y2 - dPriv->y;
+    }
+
+    driReportDamage(dPriv, rects, dPriv->numClipRects);
+    _mesa_free(rects);
 }
 
 static int driDrawableGetMSC( __DRIscreen *sPriv, __DRIdrawable *dPriv,
@@ -679,7 +692,7 @@ driCreateNewScreen(int scrn,
     static const __DRIextension *emptyExtensionList[] = { NULL };
     __DRIscreen *psp;
 
-    psp = _mesa_malloc(sizeof *psp);
+    psp = _mesa_calloc(sizeof *psp);
     if (!psp)
        return NULL;