[Xquartz-changes] xserver: Branch 'server-1.9-apple' - 4 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Mon Jul 26 12:21:58 PDT 2010


Rebased ref, commits from common ancestor:
commit b8e716df941297f765aa07179167edf88f34d718
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Feb 12 19:48:52 2010 -0800

    fb: Revert fb changes that broke XQuartz
    
    http://bugs.freedesktop.org/show_bug.cgi?id=26124
    
    Revert "Fix source pictures getting random transforms after 2d6a8f668342a5190cdf43b5."
    Revert "fb: Adjust transform or composite coordinates for pixman operations"
    
    http://bugs.freedesktop.org/26124
    
    This reverts commit a72c65e9176c51de95db2fdbf4c5d946a4911695.
    This reverts commit a6bd5d2e482a5aa84acb3d4932e2a166d8670ef1.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/fb/fb.h b/fb/fb.h
index a06f98b..3b9efea 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -2080,11 +2080,8 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
 		   FbBits	xor);
 
 extern _X_EXPORT pixman_image_t *
-image_from_pict (PicturePtr	pict,
-		 Bool		has_clip,
-		 int		*xoff,
-		 int		*yoff);
-
+image_from_pict (PicturePtr pict,
+		 Bool       has_clip);
 extern _X_EXPORT void free_pixman_pict (PicturePtr, pixman_image_t *);
 
 #endif /* _FB_H_ */
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 26cdc0d..f2ddb63 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -156,24 +156,19 @@ fbComposite (CARD8      op,
 	     CARD16     height)
 {
     pixman_image_t *src, *mask, *dest;
-    int src_xoff, src_yoff;
-    int msk_xoff, msk_yoff;
-    int dst_xoff, dst_yoff;
     
     miCompositeSourceValidate (pSrc, xSrc - xDst, ySrc - yDst, width, height);
     if (pMask)
 	miCompositeSourceValidate (pMask, xMask - xDst, yMask - yDst, width, height);
     
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    mask = image_from_pict (pMask, FALSE, &msk_xoff, &msk_yoff);
-    dest = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, TRUE);
+    mask = image_from_pict (pMask, TRUE);
+    dest = image_from_pict (pDst, TRUE);
 
     if (src && dest && !(pMask && !mask))
     {
 	pixman_image_composite (op, src, mask, dest,
-				xSrc + src_xoff, ySrc + src_yoff,
-				xMask + msk_xoff, yMask + msk_yoff,
-				xDst + dst_xoff, yDst + dst_yoff,
+				xSrc, ySrc, xMask, yMask, xDst, yDst,
 				width, height);
     }
 
@@ -271,22 +266,22 @@ create_conical_gradient_image (PictGradient *gradient)
 
 static pixman_image_t *
 create_bits_picture (PicturePtr pict,
-		     Bool       has_clip,
-		     int	*xoff,
-		     int	*yoff)
+		     Bool       has_clip)
 {
-    PixmapPtr pixmap;
     FbBits *bits;
     FbStride stride;
-    int bpp;
+    int bpp, xoff, yoff;
     pixman_image_t *image;
     
-    fbGetDrawablePixmap (pict->pDrawable, pixmap, *xoff, *yoff);
-    fbGetPixmapBitsData(pixmap, bits, stride, bpp);
+    fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff);
+
+    bits = (FbBits*)((CARD8*)bits +
+		     (pict->pDrawable->y + yoff) * stride * sizeof(FbBits) +
+		     (pict->pDrawable->x + xoff) * (bpp / 8));
 
     image = pixman_image_create_bits (
 	pict->format,
-	pixmap->drawable.width, pixmap->drawable.height,
+	pict->pDrawable->width, pict->pDrawable->height,
 	(uint32_t *)bits, stride * sizeof (FbStride));
     
     
@@ -312,52 +307,30 @@ create_bits_picture (PicturePtr pict,
 	if (pict->clientClipType != CT_NONE)
 	    pixman_image_set_has_client_clip (image, TRUE);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, *xoff, *yoff);
+	pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
 
 	pixman_image_set_clip_region (image, pict->pCompositeClip);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, -*xoff, -*yoff);
+	pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
     }
     
     /* Indexed table */
     if (pict->pFormat->index.devPrivate)
 	pixman_image_set_indexed (image, pict->pFormat->index.devPrivate);
 
-    /* Add in drawable origin to position within the image */
-    *xoff += pict->pDrawable->x;
-    *yoff += pict->pDrawable->y;
-
     return image;
 }
 
 static void
-set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+set_image_properties (pixman_image_t *image, PicturePtr pict)
 {
     pixman_repeat_t repeat;
     pixman_filter_t filter;
     
     if (pict->transform)
     {
-	/* For source images, adjust the transform to account
-	 * for the drawable offset within the pixman image,
-	 * then set the offset to 0 as it will be used
-	 * to compute positions within the transformed image.
-	 */
-	if (!has_clip) {
-	    struct pixman_transform	adjusted;
-
-	    adjusted = *pict->transform;
-	    pixman_transform_translate(&adjusted,
-				       NULL,
-				       pixman_int_to_fixed(*xoff),
-				       pixman_int_to_fixed(*yoff));
-	    pixman_image_set_transform (image, &adjusted);
-	    *xoff = 0;
-	    *yoff = 0;
-	} else
-	    pixman_image_set_transform (image, pict->transform);
+	pixman_image_set_transform (
+	    image, (pixman_transform_t *)pict->transform);
     }
     
     switch (pict->repeatType)
@@ -384,8 +357,7 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
     
     if (pict->alphaMap)
     {
-	int alpha_xoff, alpha_yoff;
-	pixman_image_t *alpha_map = image_from_pict (pict->alphaMap, FALSE, &alpha_xoff, &alpha_yoff);
+	pixman_image_t *alpha_map = image_from_pict (pict->alphaMap, TRUE);
 	
 	pixman_image_set_alpha_map (
 	    image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
@@ -418,7 +390,8 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
 }
 
 pixman_image_t *
-image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+image_from_pict (PicturePtr pict,
+		 Bool has_clip)
 {
     pixman_image_t *image = NULL;
 
@@ -427,7 +400,7 @@ image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
 
     if (pict->pDrawable)
     {
-	image = create_bits_picture (pict, has_clip, xoff, yoff);
+	image = create_bits_picture (pict, has_clip);
     }
     else if (pict->pSourcePict)
     {
@@ -448,11 +421,10 @@ image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
 	    else if (sp->type == SourcePictTypeConical)
 		image = create_conical_gradient_image (gradient);
 	}
-	*xoff = *yoff = 0;
     }
     
     if (image)
-	set_image_properties (image, pict, has_clip, xoff, yoff);
+	set_image_properties (image, pict);
     
     return image;
 }
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
index 9f5c39f..9c55236 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -38,8 +38,7 @@ fbAddTraps (PicturePtr	pPicture,
 	    int		ntrap,
 	    xTrap	*traps)
 {
-    int image_xoff, image_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &image_xoff, &image_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
@@ -55,8 +54,7 @@ fbRasterizeTrapezoid (PicturePtr    pPicture,
 		      int	    x_off,
 		      int	    y_off)
 {
-    int	mask_xoff, mask_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &mask_xoff, &mask_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
commit 60e1364184b52d3b843986d85811fd2eb6e43640
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 30 13:08:25 2010 -0700

    Workaround the GC clipping problem in miPaintWindow and add some debugging output.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 94258b8..4f25c23 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -521,6 +521,7 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
+#include "../fb/fb.h"
 #endif 
 
 void
@@ -548,24 +549,37 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool	solid = TRUE;
     DrawablePtr	drawable = &pWin->drawable;
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("START %d BS %d (pR = %ld)\n", what, pWin->backgroundState, ParentRelative);
+    ErrorF("      Rgn: %d %d %d %d\n", prgn->extents.x1, prgn->extents.y1,
+	                               prgn->extents.x2 - prgn->extents.x1,
+	                               prgn->extents.y2 - prgn->extents.y1);
+    ErrorF("      Win: %d %d (%d %d) %d %d\n", pWin->origin.x, pWin->origin.y,
+	                                       pWin->winSize.extents.x1, pWin->winSize.extents.y1,
+	                                       pWin->winSize.extents.x2 - pWin->winSize.extents.x1,
+					       pWin->winSize.extents.y2 - pWin->winSize.extents.y1);
+    ErrorF("     Draw: %d %d %d %d\n", pWin->drawable.x, pWin->drawable.y,
+				       pWin->drawable.width, pWin->drawable.height);
+#endif
+
 #ifdef ROOTLESS
     if(!drawable || drawable->type == UNDRAWABLE_WINDOW)
 	return;
-
-    if(IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-    
-        if(pWin->backgroundState == ParentRelative) {
-            if((what == PW_BACKGROUND) || 
-               (what == PW_BORDER && !pWin->borderIsPixel))
-                RootlessSetPixmapOfAncestors(pWin);
-        }
-    }
 #endif
     
     if (what == PW_BACKGROUND)
     {
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+
+	    if(pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	while (pWin->backgroundState == ParentRelative)
 	    pWin = pWin->parent;
 
@@ -587,6 +601,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     {
 	PixmapPtr   pixmap;
 
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+	    
+	    if(!pWin->borderIsPixel &&
+		pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	tile_x_off = drawable->x;
 	tile_y_off = drawable->y;
 	
@@ -595,6 +621,12 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 	    return;
 	pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
 	drawable = &pixmap->drawable;
+
+#ifdef XQUARTZ_CLIP_DEBUG
+	ErrorF("     Draw: %d %d %d %d\n",
+	       drawable->x, drawable->y, drawable->width, drawable->height);    
+#endif
+	
 #ifdef COMPOSITE
 	draw_x_off = pixmap->screen_x;
 	draw_y_off = pixmap->screen_y;
@@ -657,6 +689,57 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC (NullClient, pGC, gcmask, gcval);
     ValidateGC (drawable, pGC);
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);
+#endif
+    
+#ifdef XQUARTZ
+    /* Looks like our clipping isn't set right for some reason:
+     * http://xquartz.macosforge.org/trac/ticket/290
+     */
+    if(what == PW_BORDER) {
+
+#if 0
+	if(solid) {
+#if 1
+	    fbFillRegionSolid(&pWin->drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       pWin->drawable.bitsPerPixel));
+#else
+	    fbFillRegionSolid(drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       drawable->bitsPerPixel));
+#endif
+	    return;
+	}
+#endif
+    
+	pGC->pCompositeClip->extents.x1 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y1 += prgn->extents.y1;
+	pGC->pCompositeClip->extents.x2 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y2 += prgn->extents.y1;
+	
+	if(pGC->pCompositeClip->extents.x2 > drawable->pScreen->width)
+	    pGC->pCompositeClip->extents.x2 = drawable->pScreen->width;
+	if(pGC->pCompositeClip->extents.y2 > drawable->pScreen->height)
+	    pGC->pCompositeClip->extents.y2 = drawable->pScreen->height;
+    }
+#endif
+
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);    
+#endif
+
     numRects = RegionNumRects(prgn);
     pbox = RegionRects(prgn);
     for (i= numRects; --i >= 0; pbox++, prect++)
commit f62841c702c8595cd856d304eb5d73a0dffd67dd
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Mon Jul 26 11:45:59 2010 -0700

    XQuartz: RandR: Better handle switching betwen RandR modes that share CG modes
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index 65dce22..ced3b33 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -57,9 +57,12 @@ static Bool ignore_next_fake_mode_update = FALSE;
 #define DEFAULT_REFRESH  60
 #define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
 
-typedef Bool (*QuartzModeCallback)
-    (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
+#define CALLBACK_SUCCESS 0
+#define CALLBACK_CONTINUE 1
+#define CALLBACK_ERROR -1
 
+typedef int (*QuartzModeCallback)
+    (ScreenPtr, CGDirectDisplayID, QuartzModeInfoPtr, void *);
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
 
@@ -97,20 +100,22 @@ static void QuartzRandRGetModeInfo (CFDictionaryRef modeRef,
     pMode->ref = NULL;
 }
 
-static Bool QuartzRandRGetCurrentModeInfo (CGDirectDisplayID screenId,
+static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
                                            QuartzModeInfoPtr pMode) {
     CFDictionaryRef curModeRef = CGDisplayCurrentMode(screenId);
     if (!curModeRef)
         return FALSE;
 
     QuartzRandRGetModeInfo(curModeRef, pMode);
+    pMode->ref = curModeRef;
+    CFRetain(pMode->ref);
     return TRUE;
 }
 
 static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
                                 QuartzModeInfoPtr pMode) {
     CFDictionaryRef modeRef = (CFDictionaryRef) pMode->ref;
-    return (CGDisplaySwitchToMode(screenId, modeRef) != kCGErrorSuccess);
+    return (CGDisplaySwitchToMode(screenId, modeRef) == kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
@@ -122,6 +127,28 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     CFArrayRef modes;
     QuartzModeInfo modeInfo;
     int i;
+    BOOL retval = FALSE;
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->rootlessMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->fullScreenMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
 
     curModeRef = CGDisplayCurrentMode(screenId);
     if (!curModeRef)
@@ -132,6 +159,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     if (!modes)
         return FALSE;
     for (i = 0; i < CFArrayGetCount(modes); i++) {
+        int cb;
         modeRef = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i);
 
         /* Skip modes that are not usable on the current display or have a
@@ -144,10 +172,15 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
         QuartzRandRGetModeInfo(modeRef, &modeInfo);
         modeInfo.ref = modeRef;
-        if (!callback(pScreen, screenId, &modeInfo, data))
+        cb = callback(pScreen, screenId, &modeInfo, data);
+        if (cb == CALLBACK_SUCCESS)
+            break;
+        if (cb == CALLBACK_ERROR) {
+            retval = FALSE;
             break;
+        }
     }
-    return TRUE;
+    return retval;
 }
 
 #else /* we have the new CG APIs from Snow Leopard */
@@ -162,14 +195,14 @@ static void QuartzRandRGetModeInfo (CGDisplayModeRef modeRef,
     pMode->ref = NULL;
 }
 
-static Bool QuartzRandRGetCurrentModeInfo (CGDirectDisplayID screenId,
-                                           QuartzModeInfoPtr pMode) {
+static Bool QuartzRandRCopyCurrentModeInfo (CGDirectDisplayID screenId,
+                                            QuartzModeInfoPtr pMode) {
     CGDisplayModeRef curModeRef = CGDisplayCopyDisplayMode(screenId);
     if (!curModeRef)
         return FALSE;
 
     QuartzRandRGetModeInfo(curModeRef, pMode);
-    CGDisplayModeRelease(curModeRef);
+    pMode->ref = curModeRef;
     return TRUE;
 }
 
@@ -179,7 +212,7 @@ static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
     if (!modeRef)
         return FALSE;
 
-    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) != kCGErrorSuccess);
+    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) == kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
@@ -192,6 +225,29 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
     CFArrayRef modes;
     QuartzModeInfo modeInfo;
     int i;
+    Bool retval = TRUE;
+
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->rootlessMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
+
+    switch(callback(pScreen, screenId, &pQuartzScreen->fullScreenMode, data)) {
+        case CALLBACK_SUCCESS:
+            return TRUE;
+        case CALLBACK_ERROR:
+            return FALSE;
+        case CALLBACK_CONTINUE:
+        default:
+            break;
+    }
 
     curModeRef = CGDisplayCopyDisplayMode(screenId);
     if (!curModeRef)
@@ -205,6 +261,7 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
         return FALSE;
     }
     for (i = 0; i < CFArrayGetCount(modes); i++) {
+        int cb;
         modeRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
 
         /* Skip modes that are not usable on the current display or have a
@@ -220,13 +277,19 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
         QuartzRandRGetModeInfo(modeRef, &modeInfo);
         modeInfo.ref = modeRef;
-        if (!callback(pScreen, screenId, &modeInfo, data))
+        cb = callback(pScreen, screenId, &modeInfo, data);
+        if (cb == CALLBACK_SUCCESS)
+            break;
+		if (cb == CALLBACK_ERROR) {
+			retval = FALSE;
             break;
+		}
     }
+		
     CFRelease(modes);
 
     CFRelease(curPixelEnc);
-    return TRUE;
+    return retval;
 }
 
 #endif  /* Snow Leopard CoreGraphics APIs */
@@ -246,6 +309,7 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
     RRScreenSizePtr pSize = RRRegisterSize(pScreen,
         pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
     if (pSize) {
+        //DEBUG_LOG("registering: %d x %d @ %d %s\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh, isCurrentMode ? "*" : "");
         RRRegisterRate(pScreen, pSize, pMode->refresh);
 
         if (isCurrentMode)
@@ -256,34 +320,46 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
     return FALSE;
 }
 
-static Bool QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
+static int QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
                                         CGDirectDisplayID screenId,
                                         QuartzModeInfoPtr pMode,
                                         void *data __unused) {
-    return QuartzRandRRegisterMode(pScreen, pMode);
+    if(QuartzRandRRegisterMode(pScreen, pMode)) {
+        return CALLBACK_CONTINUE;
+    } else {
+        return CALLBACK_ERROR;
+    }
 }
 
-static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
-                                        CGDirectDisplayID screenId,
-                                        QuartzModeInfoPtr pMode,
-                                        void *data) {
+static int QuartzRandRSetModeCallback (ScreenPtr pScreen,
+                                       CGDirectDisplayID screenId,
+                                       QuartzModeInfoPtr pMode,
+                                       void *data) {
     QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data;
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-
+	
     if (!QuartzRandRModesEqual(pMode, pReqMode))
-        return TRUE;  /* continue enumeration */
+        return CALLBACK_CONTINUE;  /* continue enumeration */
+
+    DEBUG_LOG("Found a match for requested RandR resolution (%dx%d@%d).\n", (int)pMode->width, (int)pMode->height, (int)pMode->refresh);
 
-    if (pReqMode->ref == pQuartzScreen->currentMode.ref) {
+	/* Retain this mode reference, so it can be saved as currentMode */
+	CFRetain(pMode->ref);
+
+    if (pQuartzScreen->currentMode.ref && CFEqual(pMode->ref, pQuartzScreen->currentMode.ref)) {
         DEBUG_LOG("Requested RandR resolution matches current CG mode\n");
-        return FALSE; /* We don't need to do anything in CG */
+        return CALLBACK_SUCCESS; /* We don't need to do anything in CG */
     }
 
-    if (QuartzRandRSetMode(screenId, pMode) == FALSE) {
+    if (QuartzRandRSetMode(screenId, pMode)) {
+        pReqMode->ref = pMode->ref;
         ignore_next_fake_mode_update = TRUE;
-        return FALSE;
+        return CALLBACK_SUCCESS;
     } else {
-        return TRUE;
-    };
+        DEBUG_LOG("Error while requesting CG resolution change.\n");
+        CFRelease(pMode->ref);
+        return CALLBACK_ERROR;
+    }
 }
 
 static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
@@ -295,17 +371,17 @@ static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
 
-    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
-    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
-
     if (pQuartzScreen->displayCount > 1) {
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Create two entries for the current virtual
            resolution including/excluding the menu bar. */
+
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
+        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
         return TRUE;
     }
-    screenId = pQuartzScreen->displayIDs[0];
 
+    screenId = pQuartzScreen->displayIDs[0];
     return QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRRegisterModeCallback, NULL);
 }
 
@@ -342,12 +418,12 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
         
     screenId = pQuartzScreen->displayIDs[0];
     if (QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRSetModeCallback, &reqMode)) {
+        CFRelease(pQuartzScreen->currentMode.ref);
         pQuartzScreen->currentMode = reqMode;
         return TRUE;
     }
     
     DEBUG_LOG("Unable to find a matching config: %d x %d @ %d\n", (int)reqMode.width, (int)reqMode.height, (int)reqMode.refresh);
-
     return FALSE;
 }
 
@@ -355,9 +431,16 @@ static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
 
     if (pQuartzScreen->displayCount == 1) {
-        if (!QuartzRandRGetCurrentModeInfo(pQuartzScreen->displayIDs[0],
-                                           &pQuartzScreen->fullScreenMode))
+        if(pQuartzScreen->fullScreenMode.ref)
+            CFRelease(pQuartzScreen->fullScreenMode.ref);
+        if(pQuartzScreen->currentMode.ref)
+            CFRelease(pQuartzScreen->currentMode.ref);
+        
+        if (!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0],
+                                            &pQuartzScreen->fullScreenMode))
             return FALSE;
+
+        CFRetain(pQuartzScreen->fullScreenMode.ref);  /* This extra retain is for currentMode's copy */
     } else {
         pQuartzScreen->fullScreenMode.width = pScreen->width;
         pQuartzScreen->fullScreenMode.height = pScreen->height;
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index 8ee2818..4a7990e 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -34,7 +34,7 @@
 typedef struct {
     size_t width, height;
     int refresh;
-    const void *ref;
+    void *ref; /* CGDisplayModeRef or CFDictionaryRef */
 } QuartzModeInfo, *QuartzModeInfoPtr;
 
 // Quartz specific per screen storage structure
commit 9ef44fce39ab576632bd165da8c939fffb8d25f2
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Mon Jul 26 01:17:12 2010 -0700

    XQuartz: RandR: Respond better to resolution changes made outside X
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 7b34b8a..a748b69 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -276,7 +276,12 @@ static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr de
             break;
             
         case kXquartzDisplayChanged:
+            DEBUG_LOG("kXquartzDisplayChanged\n");
             QuartzUpdateScreens();
+#ifdef RANDR
+            /* Update our RandR info */
+            QuartzRandRUpdateFakeModes(TRUE);
+#endif
             break;
             
         default:
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 851e74c..718df4b 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -38,29 +38,6 @@
 #include <X11/Xdefs.h>
 #include "privates.h"
 
-typedef struct {
-    size_t width, height;
-    int refresh;
-    const void *ref;
-} QuartzModeInfo, *QuartzModeInfoPtr;
-
-// Quartz specific per screen storage structure
-typedef struct {
-    // List of CoreGraphics displays that this X11 screen covers.
-    // This is more than one CG display for video mirroring and
-    // rootless PseudoramiX mode.
-    // No CG display will be covered by more than one X11 screen.
-    int displayCount;
-    CGDirectDisplayID *displayIDs;
-    QuartzModeInfo originalMode, fakeMode;
-} QuartzScreenRec, *QuartzScreenPtr;
-
-#define QUARTZ_PRIV(pScreen) \
-    ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
-
-void QuartzCopyDisplayIDs(ScreenPtr pScreen,
-                          int displayCount, CGDirectDisplayID *displayIDs);
-
 // User preferences used by Quartz modes
 extern int              quartzUseSysBeep;
 extern int              quartzFullscreenDisableHotkeys;
diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index e46e904..65dce22 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -38,6 +38,7 @@
 #include "quartzCommon.h"
 #include "quartzRandR.h"
 #include "quartz.h"
+#include "darwin.h"
 
 #include <AvailabilityMacros.h>
 
@@ -45,6 +46,13 @@
 #include <randrstr.h>
 #include <IOKit/graphics/IOGraphicsTypes.h>
 
+/* TODO: UGLY, find a better way!
+ * We want to ignore kXquartzDisplayChanged which are generated by us
+ */
+static Bool ignore_next_fake_mode_update = FALSE;
+
+#define FAKE_REFRESH_ROOTLESS 1
+#define FAKE_REFRESH_FULLSCREEN 2
 
 #define DEFAULT_REFRESH  60
 #define kDisplayModeUsableFlags  (kDisplayModeValidFlag | kDisplayModeSafeFlag)
@@ -171,8 +179,7 @@ static Bool QuartzRandRSetMode (CGDirectDisplayID screenId,
     if (!modeRef)
         return FALSE;
 
-    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) !=
-            kCGErrorSuccess);
+    return (CGDisplaySetDisplayMode(screenId, modeRef, NULL) != kCGErrorSuccess);
 }
 
 static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
@@ -227,18 +234,15 @@ static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
 
 static Bool QuartzRandRModesEqual (QuartzModeInfoPtr pMode1,
                                    QuartzModeInfoPtr pMode2) {
-    if (pMode1->width != pMode2->width)
-        return FALSE;
-    if (pMode1->height != pMode2->height)
-        return FALSE;
-    if (pMode1->refresh != pMode2->refresh)
-        return FALSE;
-    return TRUE;
+    return (pMode1->width == pMode2->width) &&
+           (pMode1->height == pMode2->height) &&
+           (pMode1->refresh == pMode2->refresh);
 }
 
 static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
-                                     QuartzModeInfoPtr pMode,
-                                     Bool isCurrentMode) {
+                                     QuartzModeInfoPtr pMode) {
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    Bool isCurrentMode = QuartzRandRModesEqual(&pQuartzScreen->currentMode, pMode);
     RRScreenSizePtr pSize = RRRegisterSize(pScreen,
         pMode->width, pMode->height, pScreen->mmWidth, pScreen->mmHeight);
     if (pSize) {
@@ -252,14 +256,11 @@ static Bool QuartzRandRRegisterMode (ScreenPtr pScreen,
     return FALSE;
 }
 
-static Bool QuartzRandRGetModeCallback (ScreenPtr pScreen,
+static Bool QuartzRandRRegisterModeCallback (ScreenPtr pScreen,
                                         CGDirectDisplayID screenId,
                                         QuartzModeInfoPtr pMode,
-                                        void *data) {
-    QuartzModeInfoPtr pCurMode = (QuartzModeInfoPtr) data;
-
-    return QuartzRandRRegisterMode(pScreen, pMode,
-        QuartzRandRModesEqual(pMode, pCurMode));
+                                        void *data __unused) {
+    return QuartzRandRRegisterMode(pScreen, pMode);
 }
 
 static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
@@ -267,73 +268,64 @@ static Bool QuartzRandRSetModeCallback (ScreenPtr pScreen,
                                         QuartzModeInfoPtr pMode,
                                         void *data) {
     QuartzModeInfoPtr pReqMode = (QuartzModeInfoPtr) data;
+    QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
 
     if (!QuartzRandRModesEqual(pMode, pReqMode))
         return TRUE;  /* continue enumeration */
 
-    return QuartzRandRSetMode(screenId, pMode);
+    if (pReqMode->ref == pQuartzScreen->currentMode.ref) {
+        DEBUG_LOG("Requested RandR resolution matches current CG mode\n");
+        return FALSE; /* We don't need to do anything in CG */
+    }
+
+    if (QuartzRandRSetMode(screenId, pMode) == FALSE) {
+        ignore_next_fake_mode_update = TRUE;
+        return FALSE;
+    } else {
+        return TRUE;
+    };
 }
 
 static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     CGDirectDisplayID screenId;
-    QuartzModeInfo curMode;
 
     *rotations = RR_Rotate_0;  /* TODO: support rotation */
 
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
+
+    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->rootlessMode);
+    QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fullScreenMode);
+
     if (pQuartzScreen->displayCount > 1) {
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Create two entries for the current virtual
            resolution including/excluding the menu bar. */
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode,
-            !quartzHasRoot);
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->originalMode,
-            quartzHasRoot);
         return TRUE;
     }
     screenId = pQuartzScreen->displayIDs[0];
 
-    if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
-        return FALSE;
-
-    /* Add a fake mode corresponding to the original resolution excluding the
-       height of the menu bar. */
-    if (!quartzHasRoot &&
-        QuartzRandRModesEqual(&pQuartzScreen->originalMode, &curMode)) {
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, TRUE);
-        curMode = pQuartzScreen->fakeMode;
-    }
-    else
-        QuartzRandRRegisterMode(pScreen, &pQuartzScreen->fakeMode, FALSE);
-
-    return QuartzRandREnumerateModes(pScreen, screenId,
-        QuartzRandRGetModeCallback, &curMode);
+    return QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRRegisterModeCallback, NULL);
 }
 
 static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
-			          Rotation            randr,
-			          int                 rate,
-			          RRScreenSizePtr     pSize) {
+                                  Rotation            randr,
+                                  int                 rate,
+                                  RRScreenSizePtr     pSize) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     CGDirectDisplayID screenId;
-    QuartzModeInfo reqMode, curMode;
-    Bool rootless = FALSE;
+    QuartzModeInfo reqMode;
 
     reqMode.width = pSize->width;
     reqMode.height = pSize->height;
     reqMode.refresh = rate;
 
-    /* If the client requested the fake screen mode, switch to rootless mode.
-       Switch to fullscreen mode (root window visible) if a real screen mode was
-       requested. */
-    if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->fakeMode)) {
-        rootless = TRUE;
-        reqMode = pQuartzScreen->originalMode;
-    }
-    QuartzSetFullscreen(!rootless);
-    QuartzSetRootless(rootless);
+    /* If the client requested the fake rootless mode, switch to rootless.
+     * Otherwise, force fullscreen mode.
+     */
+    QuartzSetFullscreen(reqMode.refresh != FAKE_REFRESH_ROOTLESS);
+    QuartzSetRootless(reqMode.refresh == FAKE_REFRESH_ROOTLESS);
 
     if (pQuartzScreen->displayCount == 0)
         return FALSE;
@@ -341,38 +333,80 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
         /* RandR operations are not well-defined for an X11 screen spanning
            multiple CG displays. Do not accept any configuations that differ
            from the current configuration. */
-        return QuartzRandRModesEqual(&reqMode, &pQuartzScreen->originalMode);
+        return TRUE;
     }
-    screenId = pQuartzScreen->displayIDs[0];
 
     /* Do not switch modes if requested mode is equal to current mode. */
-    if (!QuartzRandRGetCurrentModeInfo(screenId, &curMode))
-        return FALSE;
-    if (QuartzRandRModesEqual(&reqMode, &curMode))
+    if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->currentMode))
         return TRUE;
+        
+    screenId = pQuartzScreen->displayIDs[0];
+    if (QuartzRandREnumerateModes(pScreen, screenId, QuartzRandRSetModeCallback, &reqMode)) {
+        pQuartzScreen->currentMode = reqMode;
+        return TRUE;
+    }
+    
+    DEBUG_LOG("Unable to find a matching config: %d x %d @ %d\n", (int)reqMode.width, (int)reqMode.height, (int)reqMode.refresh);
 
-    return QuartzRandREnumerateModes(pScreen, screenId,
-        QuartzRandRSetModeCallback, &reqMode);
+    return FALSE;
 }
 
-Bool QuartzRandRInit (ScreenPtr pScreen) {
-    rrScrPrivPtr    pScrPriv;
+static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-    
-    if (!RRScreenInit (pScreen)) return FALSE;
 
     if (pQuartzScreen->displayCount == 1) {
         if (!QuartzRandRGetCurrentModeInfo(pQuartzScreen->displayIDs[0],
-                                           &pQuartzScreen->originalMode))
+                                           &pQuartzScreen->fullScreenMode))
             return FALSE;
+    } else {
+        pQuartzScreen->fullScreenMode.width = pScreen->width;
+        pQuartzScreen->fullScreenMode.height = pScreen->height;
+        if(quartzEnableRootless)
+            pQuartzScreen->fullScreenMode.height += aquaMenuBarHeight;
     }
-    else {
-        pQuartzScreen->originalMode.width = pScreen->width;
-        pQuartzScreen->originalMode.height = pScreen->height;
-        pQuartzScreen->originalMode.refresh = DEFAULT_REFRESH;
+
+    pQuartzScreen->fullScreenMode.refresh = FAKE_REFRESH_FULLSCREEN;
+
+    pQuartzScreen->rootlessMode = pQuartzScreen->fullScreenMode;
+    pQuartzScreen->rootlessMode.refresh = FAKE_REFRESH_ROOTLESS;
+    pQuartzScreen->rootlessMode.height -= aquaMenuBarHeight;
+
+    if(quartzEnableRootless) {
+        pQuartzScreen->currentMode = pQuartzScreen->rootlessMode;
+    } else {
+        pQuartzScreen->currentMode = pQuartzScreen->fullScreenMode;
     }
-    pQuartzScreen->fakeMode = pQuartzScreen->originalMode;
-    pQuartzScreen->fakeMode.height -= aquaMenuBarHeight;
+    
+    DEBUG_LOG("rootlessMode: %d x %d\n", (int)pQuartzScreen->rootlessMode.width, (int)pQuartzScreen->rootlessMode.height);
+    DEBUG_LOG("fullScreenMode: %d x %d\n", (int)pQuartzScreen->fullScreenMode.width, (int)pQuartzScreen->fullScreenMode.height);
+    DEBUG_LOG("currentMode: %d x %d\n", (int)pQuartzScreen->currentMode.width, (int)pQuartzScreen->currentMode.height);
+    
+    return TRUE;
+}
+
+Bool QuartzRandRUpdateFakeModes (BOOL force_update) {
+    ScreenPtr pScreen = screenInfo.screens[0];
+    
+    if(ignore_next_fake_mode_update) {
+        DEBUG_LOG("Ignoring update request caused by RandR resolution change.\n");
+        ignore_next_fake_mode_update = FALSE;
+        return TRUE;
+    }
+    
+    if(!_QuartzRandRUpdateFakeModes(pScreen))
+        return FALSE;
+    
+    if(force_update)
+        RRGetInfo(pScreen, TRUE);
+
+    return TRUE;
+}
+
+Bool QuartzRandRInit (ScreenPtr pScreen) {
+    rrScrPrivPtr    pScrPriv;
+    
+    if (!RRScreenInit (pScreen)) return FALSE;
+    if (!_QuartzRandRUpdateFakeModes (pScreen)) return FALSE;
 
     pScrPriv = rrGetScrPriv(pScreen);
     pScrPriv->rrGetInfo = QuartzRandRGetInfo;
diff --git a/hw/xquartz/quartzRandR.h b/hw/xquartz/quartzRandR.h
index d57dc3b..8ee2818 100644
--- a/hw/xquartz/quartzRandR.h
+++ b/hw/xquartz/quartzRandR.h
@@ -31,6 +31,30 @@
 #ifndef _QUARTZRANDR_H_
 #define _QUARTZRANDR_H_
 
+typedef struct {
+    size_t width, height;
+    int refresh;
+    const void *ref;
+} QuartzModeInfo, *QuartzModeInfoPtr;
+
+// Quartz specific per screen storage structure
+typedef struct {
+    // List of CoreGraphics displays that this X11 screen covers.
+    // This is more than one CG display for video mirroring and
+    // rootless PseudoramiX mode.
+    // No CG display will be covered by more than one X11 screen.
+    int displayCount;
+    CGDirectDisplayID *displayIDs;
+    QuartzModeInfo rootlessMode, fullScreenMode, currentMode;
+} QuartzScreenRec, *QuartzScreenPtr;
+
+#define QUARTZ_PRIV(pScreen) \
+    ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
+
+void QuartzCopyDisplayIDs(ScreenPtr pScreen,
+                          int displayCount, CGDirectDisplayID *displayIDs);
+
+Bool QuartzRandRUpdateFakeModes (BOOL force_update);
 Bool QuartzRandRInit (ScreenPtr pScreen);
 
 #endif


More information about the Xquartz-changes mailing list