xserver: Branch 'master' - 9 commits

Maarten Maathuis madman2003 at kemper.freedesktop.org
Fri Feb 6 09:44:19 PST 2009


 exa/exa.c         |  383 ++++++++++++++++++++++++++++++++++--------------------
 exa/exa_accel.c   |  254 ++++++++++-------------------------
 exa/exa_priv.h    |   70 +++++++++
 exa/exa_render.c  |   17 +-
 exa/exa_unaccel.c |  208 ++++++++++++++++++++++-------
 fb/fb.h           |   37 -----
 fb/fbcopy.c       |  331 ----------------------------------------------
 fb/fboverlay.c    |    2 
 fb/fboverlay.h    |    2 
 fb/fbwindow.c     |    2 
 mi/Makefile.am    |    1 
 mi/mi.h           |   42 +++++
 mi/micopy.c       |  354 +++++++++++++++++++++++++++++++++++++++++++++++++
 13 files changed, 961 insertions(+), 742 deletions(-)

New commits:
commit 68665d78e72c4c564073d66a0f59ac8d3f5fd756
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Thu Feb 5 17:07:31 2009 +0100

    exa: don't use fbCopyNtoN

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index cc5dd18..326720f 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -359,8 +359,8 @@ exaCopyNtoNTwoDir (DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
     return TRUE;
 }
 
-void
-exaCopyNtoN (DrawablePtr    pSrcDrawable,
+Bool
+exaHWCopyNtoN (DrawablePtr    pSrcDrawable,
 	     DrawablePtr    pDstDrawable,
 	     GCPtr	    pGC,
 	     BoxPtr	    pbox,
@@ -368,9 +368,7 @@ exaCopyNtoN (DrawablePtr    pSrcDrawable,
 	     int	    dx,
 	     int	    dy,
 	     Bool	    reverse,
-	     Bool	    upsidedown,
-	     Pixel	    bitplane,
-	     void	    *closure)
+	     Bool	    upsidedown)
 {
     ExaScreenPriv (pDstDrawable->pScreen);
     PixmapPtr pSrcPixmap, pDstPixmap;
@@ -380,10 +378,11 @@ exaCopyNtoN (DrawablePtr    pSrcDrawable,
     ExaMigrationRec pixmaps[2];
     RegionPtr srcregion = NULL, dstregion = NULL;
     xRectangle *rects;
+    Bool ret = TRUE;
 
     /* avoid doing copy operations if no boxes */
     if (nbox == 0)
-	return;
+	return TRUE;
 
     pSrcPixmap = exaGetDrawablePixmap (pSrcDrawable);
     pDstPixmap = exaGetDrawablePixmap (pDstDrawable);
@@ -492,15 +491,7 @@ exaCopyNtoN (DrawablePtr    pSrcDrawable,
     goto out;
 
 fallback:
-    EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrcDrawable, pDstDrawable,
-		  exaDrawableLocation(pSrcDrawable),
-		  exaDrawableLocation(pDstDrawable)));
-    exaPrepareAccessReg (pDstDrawable, EXA_PREPARE_DEST, dstregion);
-    exaPrepareAccessReg (pSrcDrawable, EXA_PREPARE_SRC, srcregion);
-    fbCopyNtoN (pSrcDrawable, pDstDrawable, pGC, pbox, nbox, dx, dy, reverse,
-		upsidedown, bitplane, closure);
-    exaFinishAccess (pSrcDrawable, EXA_PREPARE_SRC);
-    exaFinishAccess (pDstDrawable, EXA_PREPARE_DEST);
+    ret = FALSE;
 
 out:
     if (dstregion) {
@@ -511,6 +502,52 @@ out:
 	REGION_UNINIT(pScreen, srcregion);
 	REGION_DESTROY(pScreen, srcregion);
     }
+
+    return ret;
+}
+
+void
+exaCopyNtoN (DrawablePtr    pSrcDrawable,
+	     DrawablePtr    pDstDrawable,
+	     GCPtr	    pGC,
+	     BoxPtr	    pbox,
+	     int	    nbox,
+	     int	    dx,
+	     int	    dy,
+	     Bool	    reverse,
+	     Bool	    upsidedown,
+	     Pixel	    bitplane,
+	     void	    *closure)
+{
+    ExaScreenPriv(pDstDrawable->pScreen);
+
+    if (pExaScr->fallback_flags & EXA_FALLBACK_COPYWINDOW)
+	return;
+
+    if (exaHWCopyNtoN(pSrcDrawable, pDstDrawable, pGC, pbox, nbox, dx, dy, reverse, upsidedown))
+	return;
+
+    /* This is a CopyWindow, it's cleaner to fallback at the original call. */
+    if (pExaScr->fallback_flags & EXA_ACCEL_COPYWINDOW) {
+	pExaScr->fallback_flags |= EXA_FALLBACK_COPYWINDOW;
+	return;
+    }
+
+    /* We need a pGC to call our fallback. */
+    if (!pGC) {
+	pExaScr->fallback_flags |= EXA_FALLBACK_NOGC;
+	pGC = CreateScratchGC(pDstDrawable->pScreen, pDstDrawable->depth);
+	if (!pGC)
+	    return;
+    }
+
+    /* fallback */
+    ExaCheckCopyNtoN(pSrcDrawable, pDstDrawable, pGC, pbox, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
+
+    if (pExaScr->fallback_flags & EXA_FALLBACK_NOGC) {
+	pExaScr->fallback_flags &= ~EXA_FALLBACK_NOGC;
+	FreeScratchGC(pGC);
+    }
 }
 
 RegionPtr
@@ -865,6 +902,7 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     RegionRec	rgnDst;
     int		dx, dy;
     PixmapPtr	pPixmap = (*pWin->drawable.pScreen->GetWindowPixmap) (pWin);
+    ExaScreenPriv(pWin->drawable.pScreen);
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
@@ -879,11 +917,19 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 			  -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
 
+    pExaScr->fallback_flags |= EXA_ACCEL_COPYWINDOW;
     miCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
 		  NULL,
 		  &rgnDst, dx, dy, exaCopyNtoN, 0, NULL);
+    pExaScr->fallback_flags &= ~EXA_ACCEL_COPYWINDOW;
 
     REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+
+    if (pExaScr->fallback_flags & EXA_FALLBACK_COPYWINDOW) {
+	pExaScr->fallback_flags &= ~EXA_FALLBACK_COPYWINDOW;
+	REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, dx, dy);
+	ExaCheckCopyWindow(pWin, ptOldOrg, prgnSrc);
+    }
 }
 
 static Bool
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 6d7c1dd..588fdec 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -127,6 +127,10 @@ typedef struct {
 
 #define EXA_NUM_GLYPH_CACHES 4
 
+#define EXA_FALLBACK_COPYWINDOW (1 << 0)
+#define EXA_ACCEL_COPYWINDOW (1 << 1)
+#define EXA_FALLBACK_NOGC (1 << 2)
+
 typedef void (*EnableDisableFBAccessProcPtr)(int, Bool);
 typedef struct {
     ExaDriverPtr info;
@@ -155,6 +159,8 @@ typedef struct {
     unsigned			 disableFbCount;
     Bool			 optimize_migration;
     unsigned			 offScreenCounter;
+    /* Holds information on fallbacks that cannot be relayed otherwise. */
+    unsigned int fallback_flags;
 
     ExaGlyphCacheRec             glyphCaches[EXA_NUM_GLYPH_CACHES];
 } ExaScreenPrivRec, *ExaScreenPrivPtr;
@@ -316,6 +322,11 @@ ExaCheckPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth,
 		 int x, int y, int w, int h, int leftPad, int format,
 		 char *bits);
 
+void
+ExaCheckCopyNtoN (DrawablePtr pSrc, DrawablePtr pDst,  GCPtr pGC,
+	     BoxPtr	pbox, int nbox, int dx, int dy, Bool	reverse, 
+	     Bool upsidedown, Pixel bitplane, void *closure);
+
 RegionPtr
 ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 		 int srcx, int srcy, int w, int h, int dstx, int dsty);
@@ -361,6 +372,9 @@ ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
 		   int w, int h, int x, int y);
 
 void
+ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
+
+void
 ExaCheckGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
 		unsigned int format, unsigned long planeMask, char *d);
 
@@ -465,6 +479,17 @@ RegionPtr
 exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
 	    int srcx, int srcy, int width, int height, int dstx, int dsty);
 
+Bool
+exaHWCopyNtoN (DrawablePtr    pSrcDrawable,
+	     DrawablePtr    pDstDrawable,
+	     GCPtr	    pGC,
+	     BoxPtr	    pbox,
+	     int	    nbox,
+	     int	    dx,
+	     int	    dy,
+	     Bool	    reverse,
+	     Bool	    upsidedown);
+
 void
 exaCopyNtoN (DrawablePtr    pSrcDrawable,
 	     DrawablePtr    pDstDrawable,
diff --git a/exa/exa_render.c b/exa/exa_render.c
index 63ea5c1..1788531 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -851,6 +851,7 @@ exaComposite(CARD8	op,
 		     !pSrc->repeat &&
 		     !pSrc->transform)
 	    {
+		Bool ret;
 		xDst += pDst->pDrawable->x;
 		yDst += pDst->pDrawable->y;
 		xSrc += pSrc->pDrawable->x;
@@ -861,12 +862,20 @@ exaComposite(CARD8	op,
 					       yDst, width, height))
 		    goto done;
 
-
-		exaCopyNtoN (pSrc->pDrawable, pDst->pDrawable, NULL,
+		ret = exaHWCopyNtoN(pSrc->pDrawable, pDst->pDrawable, NULL,
 			     REGION_RECTS(&region), REGION_NUM_RECTS(&region),
-			     xSrc - xDst, ySrc - yDst,
-			     FALSE, FALSE, 0, NULL);
+			     xSrc - xDst, ySrc - yDst, FALSE, FALSE);
 		REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+
+		/* Reset values to their original values. */
+		xDst -= pDst->pDrawable->x;
+		yDst -= pDst->pDrawable->y;
+		xSrc -= pSrc->pDrawable->x;
+		ySrc -= pSrc->pDrawable->y;
+
+		if (!ret)
+		    goto fallback;
+
 		goto done;
 	    }
 	    else if (pSrc->pDrawable != NULL &&
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index e0f2ae9..978a32f 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -116,6 +116,40 @@ ExaCheckPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth,
     EXA_GC_EPILOGUE(pGC);
 }
 
+/* Sometimes we need a pGC to call a function, but don't actually want the lower
+ * layer to do something with the contents of this fake GC. */
+static inline GCPtr
+ExaCheckWantGC(DrawablePtr pDrawable, GCPtr pGC)
+{
+    ExaScreenPriv(pDrawable->pScreen);
+
+    if (pExaScr->fallback_flags & EXA_FALLBACK_NOGC)
+	return NULL;
+
+    return pGC;
+}
+
+void
+ExaCheckCopyNtoN (DrawablePtr pSrc, DrawablePtr pDst,  GCPtr pGC,
+	     BoxPtr	pbox, int nbox, int dx, int dy, Bool	reverse, 
+	     Bool upsidedown, Pixel bitplane, void *closure)
+{
+    EXA_GC_PROLOGUE(pGC);
+    EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrc, pDst,
+		  exaDrawableLocation(pSrc), exaDrawableLocation(pDst)));
+    exaPrepareAccess (pDst, EXA_PREPARE_DEST);
+    exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
+    /* This will eventually call fbCopyNtoN, with some calculation overhead. */
+    while (nbox--) {
+	pGC->ops->CopyArea (pSrc, pDst, ExaCheckWantGC(pDst, pGC), pbox->x1 - pSrc->x + dx, pbox->y1 - pSrc->y + dy, 
+			pbox->x2 - pbox->x1, pbox->y2 - pbox->y1, pbox->x1 - pDst->x, pbox->y1 - pDst->y);
+	pbox++;
+    }
+    exaFinishAccess (pSrc, EXA_PREPARE_SRC);
+    exaFinishAccess (pDst, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
+}
+
 RegionPtr
 ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 		 int srcx, int srcy, int w, int h, int dstx, int dsty)
@@ -283,6 +317,22 @@ ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
 }
 
 void
+ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
+{
+    DrawablePtr pDrawable = &pWin->drawable;
+    ScreenPtr pScreen = pDrawable->pScreen;
+    ExaScreenPriv(pScreen);
+    EXA_FALLBACK(("from %p\n", pWin));
+
+    /* being both src and dest, src is safest. */
+    exaPrepareAccess(pDrawable, EXA_PREPARE_SRC);
+    swap(pExaScr, pScreen, CopyWindow);
+    pScreen->CopyWindow (pWin, ptOldOrg, prgnSrc);
+    swap(pExaScr, pScreen, CopyWindow);
+    exaFinishAccess (pDrawable, EXA_PREPARE_SRC);
+}
+
+void
 ExaCheckGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
 		unsigned int format, unsigned long planeMask, char *d)
 {
commit 2e76958d304a3c4080d62f32449724eeb9b95d93
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Wed Feb 4 19:48:03 2009 +0100

    fb: move some code to mi

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 02858f1..cc5dd18 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -524,7 +524,7 @@ exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
                                  srcx, srcy, width, height, dstx, dsty);
     }
 
-    return  fbDoCopy (pSrcDrawable, pDstDrawable, pGC,
+    return  miDoCopy (pSrcDrawable, pDstDrawable, pGC,
                       srcx, srcy, width, height,
                       dstx, dsty, exaCopyNtoN, 0, NULL);
 }
@@ -879,7 +879,7 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 			  -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
 
-    fbCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
+    miCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
 		  NULL,
 		  &rgnDst, dx, dy, exaCopyNtoN, 0, NULL);
 
diff --git a/fb/fb.h b/fb/fb.h
index 8384315..cadb9a0 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1306,18 +1306,6 @@ fbInitVisuals (VisualPtr    *visualp,
  * fbcopy.c
  */
 
-typedef void	(*fbCopyProc) (DrawablePtr  pSrcDrawable,
-			       DrawablePtr  pDstDrawable,
-			       GCPtr	    pGC,
-			       BoxPtr	    pDstBox,
-			       int	    nbox,
-			       int	    dx,
-			       int	    dy,
-			       Bool	    reverse,
-			       Bool	    upsidedown,
-			       Pixel	    bitplane,
-			       void	    *closure);
-
 extern _X_EXPORT void
 fbCopyNtoN (DrawablePtr	pSrcDrawable,
 	    DrawablePtr	pDstDrawable,
@@ -1357,31 +1345,6 @@ fbCopyNto1 (DrawablePtr	pSrcDrawable,
 	    Pixel	bitplane,
 	    void	*closure);
 
-extern _X_EXPORT void
-fbCopyRegion (DrawablePtr   pSrcDrawable,
-	      DrawablePtr   pDstDrawable,
-	      GCPtr	    pGC,
-	      RegionPtr	    pDstRegion,
-	      int	    dx,
-	      int	    dy,
-	      fbCopyProc    copyProc,
-	      Pixel	    bitPlane,
-	      void	    *closure);
-
-extern _X_EXPORT RegionPtr
-fbDoCopy (DrawablePtr	pSrcDrawable,
-	  DrawablePtr	pDstDrawable,
-	  GCPtr		pGC,
-	  int		xIn, 
-	  int		yIn,
-	  int		widthSrc, 
-	  int		heightSrc,
-	  int		xOut, 
-	  int		yOut,
-	  fbCopyProc	copyProc,
-	  Pixel		bitplane,
-	  void		*closure);
-	  
 extern _X_EXPORT RegionPtr
 fbCopyArea (DrawablePtr	pSrcDrawable,
 	    DrawablePtr	pDstDrawable,
diff --git a/fb/fbcopy.c b/fb/fbcopy.c
index b8b0b6a..fed87a5 100644
--- a/fb/fbcopy.c
+++ b/fb/fbcopy.c
@@ -289,329 +289,6 @@ fbCopyNto1 (DrawablePtr	pSrcDrawable,
     }
 }
 
-void
-fbCopyRegion (DrawablePtr   pSrcDrawable,
-	      DrawablePtr   pDstDrawable,
-	      GCPtr	    pGC,
-	      RegionPtr	    pDstRegion,
-	      int	    dx,
-	      int	    dy,
-	      fbCopyProc    copyProc,
-	      Pixel	    bitPlane,
-	      void	    *closure)
-{
-    int		careful;
-    Bool	reverse;
-    Bool	upsidedown;
-    BoxPtr	pbox;
-    int		nbox;
-    BoxPtr	pboxNew1, pboxNew2, pboxBase, pboxNext, pboxTmp;
-    
-    pbox = REGION_RECTS(pDstRegion);
-    nbox = REGION_NUM_RECTS(pDstRegion);
-    
-    /* XXX we have to err on the side of safety when both are windows,
-     * because we don't know if IncludeInferiors is being used.
-     */
-    careful = ((pSrcDrawable == pDstDrawable) ||
-	       ((pSrcDrawable->type == DRAWABLE_WINDOW) &&
-		(pDstDrawable->type == DRAWABLE_WINDOW)));
-
-    pboxNew1 = NULL;
-    pboxNew2 = NULL;
-    if (careful && dy < 0)
-    {
-	upsidedown = TRUE;
-
-	if (nbox > 1)
-	{
-	    /* keep ordering in each band, reverse order of bands */
-	    pboxNew1 = (BoxPtr)xalloc(sizeof(BoxRec) * nbox);
-	    if(!pboxNew1)
-		return;
-	    pboxBase = pboxNext = pbox+nbox-1;
-	    while (pboxBase >= pbox)
-	    {
-		while ((pboxNext >= pbox) &&
-		       (pboxBase->y1 == pboxNext->y1))
-		    pboxNext--;
-		pboxTmp = pboxNext+1;
-		while (pboxTmp <= pboxBase)
-		{
-		    *pboxNew1++ = *pboxTmp++;
-		}
-		pboxBase = pboxNext;
-	    }
-	    pboxNew1 -= nbox;
-	    pbox = pboxNew1;
-	}
-    }
-    else
-    {
-	/* walk source top to bottom */
-	upsidedown = FALSE;
-    }
-
-    if (careful && dx < 0)
-    {
-	/* walk source right to left */
-	if (dy <= 0)
-	    reverse = TRUE;
-	else
-	    reverse = FALSE;
-
-	if (nbox > 1)
-	{
-	    /* reverse order of rects in each band */
-	    pboxNew2 = (BoxPtr)xalloc(sizeof(BoxRec) * nbox);
-	    if(!pboxNew2)
-	    {
-		if (pboxNew1)
-		    xfree(pboxNew1);
-		return;
-	    }
-	    pboxBase = pboxNext = pbox;
-	    while (pboxBase < pbox+nbox)
-	    {
-		while ((pboxNext < pbox+nbox) &&
-		       (pboxNext->y1 == pboxBase->y1))
-		    pboxNext++;
-		pboxTmp = pboxNext;
-		while (pboxTmp != pboxBase)
-		{
-		    *pboxNew2++ = *--pboxTmp;
-		}
-		pboxBase = pboxNext;
-	    }
-	    pboxNew2 -= nbox;
-	    pbox = pboxNew2;
-	}
-    }
-    else
-    {
-	/* walk source left to right */
-	reverse = FALSE;
-    }
-
-    (*copyProc) (pSrcDrawable,
-		 pDstDrawable,
-		 pGC,
-		 pbox,
-		 nbox,
-		 dx, dy,
-		 reverse, upsidedown, bitPlane, closure);
-    
-    if (pboxNew1)
-	xfree (pboxNew1);
-    if (pboxNew2)
-	xfree (pboxNew2);
-}
-
-RegionPtr
-fbDoCopy (DrawablePtr	pSrcDrawable,
-	  DrawablePtr	pDstDrawable,
-	  GCPtr		pGC,
-	  int		xIn, 
-	  int		yIn,
-	  int		widthSrc, 
-	  int		heightSrc,
-	  int		xOut, 
-	  int		yOut,
-	  fbCopyProc	copyProc,
-	  Pixel		bitPlane,
-	  void		*closure)
-{
-    RegionPtr	prgnSrcClip = NULL; /* may be a new region, or just a copy */
-    Bool	freeSrcClip = FALSE;
-    RegionPtr	prgnExposed = NULL;
-    RegionRec	rgnDst;
-    int		dx;
-    int		dy;
-    int		numRects;
-    int         box_x1;
-    int         box_y1;
-    int         box_x2;
-    int         box_y2;
-    Bool	fastSrc = FALSE;    /* for fast clipping with pixmap source */
-    Bool	fastDst = FALSE;    /* for fast clipping with one rect dest */
-    Bool	fastExpose = FALSE; /* for fast exposures with pixmap source */
-
-    /* Short cut for unmapped windows */
-
-    if (pDstDrawable->type == DRAWABLE_WINDOW && 
-	!((WindowPtr)pDstDrawable)->realized)
-    {
-	return NULL;
-    }
-
-    if ((pSrcDrawable != pDstDrawable) &&
-	pSrcDrawable->pScreen->SourceValidate)
-    {
-	(*pSrcDrawable->pScreen->SourceValidate) (pSrcDrawable, xIn, yIn, widthSrc, heightSrc);
-    }
-
-    /* Compute source clip region */
-    if (pSrcDrawable->type == DRAWABLE_PIXMAP)
-    {
-	if ((pSrcDrawable == pDstDrawable) && (pGC->clientClipType == CT_NONE))
-	    prgnSrcClip = fbGetCompositeClip(pGC);
-	else
-	    fastSrc = TRUE;
-    }
-    else
-    {
-	if (pGC->subWindowMode == IncludeInferiors)
-	{
-	    /*
-	     * XFree86 DDX empties the border clip when the
-	     * VT is inactive, make sure the region isn't empty
-	     */
-	    if (!((WindowPtr) pSrcDrawable)->parent &&
-		REGION_NOTEMPTY (pSrcDrawable->pScreen,
-				 &((WindowPtr) pSrcDrawable)->borderClip))
-	    {
-		/*
-		 * special case bitblt from root window in
-		 * IncludeInferiors mode; just like from a pixmap
-		 */
-		fastSrc = TRUE;
-	    }
-	    else if ((pSrcDrawable == pDstDrawable) &&
-		     (pGC->clientClipType == CT_NONE))
-	    {
-		prgnSrcClip = fbGetCompositeClip(pGC);
-	    }
-	    else
-	    {
-		prgnSrcClip = NotClippedByChildren((WindowPtr)pSrcDrawable);
-		freeSrcClip = TRUE;
-	    }
-	}
-	else
-	{
-	    prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList;
-	}
-    }
-
-    xIn += pSrcDrawable->x;
-    yIn += pSrcDrawable->y;
-    
-    xOut += pDstDrawable->x;
-    yOut += pDstDrawable->y;
-
-    box_x1 = xIn;
-    box_y1 = yIn;
-    box_x2 = xIn + widthSrc;
-    box_y2 = yIn + heightSrc;
-
-    dx = xIn - xOut;
-    dy = yIn - yOut;
-
-    /* Don't create a source region if we are doing a fast clip */
-    if (fastSrc)
-    {
-	RegionPtr cclip;
-    
-	fastExpose = TRUE;
-	/*
-	 * clip the source; if regions extend beyond the source size,
- 	 * make sure exposure events get sent
-	 */
-	if (box_x1 < pSrcDrawable->x)
-	{
-	    box_x1 = pSrcDrawable->x;
-	    fastExpose = FALSE;
-	}
-	if (box_y1 < pSrcDrawable->y)
-	{
-	    box_y1 = pSrcDrawable->y;
-	    fastExpose = FALSE;
-	}
-	if (box_x2 > pSrcDrawable->x + (int) pSrcDrawable->width)
-	{
-	    box_x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
-	    fastExpose = FALSE;
-	}
-	if (box_y2 > pSrcDrawable->y + (int) pSrcDrawable->height)
-	{
-	    box_y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
-	    fastExpose = FALSE;
-	}
-	
-	/* Translate and clip the dst to the destination composite clip */
-        box_x1 -= dx;
-        box_x2 -= dx;
-        box_y1 -= dy;
-        box_y2 -= dy;
-
-	/* If the destination composite clip is one rectangle we can
-	   do the clip directly.  Otherwise we have to create a full
-	   blown region and call intersect */
-
-	cclip = fbGetCompositeClip(pGC);
-        if (REGION_NUM_RECTS(cclip) == 1)
-        {
-	    BoxPtr pBox = REGION_RECTS(cclip);
-
-	    if (box_x1 < pBox->x1) box_x1 = pBox->x1;
-	    if (box_x2 > pBox->x2) box_x2 = pBox->x2;
-	    if (box_y1 < pBox->y1) box_y1 = pBox->y1;
-	    if (box_y2 > pBox->y2) box_y2 = pBox->y2;
-	    fastDst = TRUE;
-	}
-    }
-    
-    /* Check to see if the region is empty */
-    if (box_x1 >= box_x2 || box_y1 >= box_y2)
-    {
-	REGION_NULL(pGC->pScreen, &rgnDst);
-    }
-    else
-    {
-        BoxRec	box;
-	box.x1 = box_x1;
-	box.y1 = box_y1;
-	box.x2 = box_x2;
-	box.y2 = box_y2;
-	REGION_INIT(pGC->pScreen, &rgnDst, &box, 1);
-    }
-    
-    /* Clip against complex source if needed */
-    if (!fastSrc)
-    {
-	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip);
-	REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy);
-    }
-
-    /* Clip against complex dest if needed */
-    if (!fastDst)
-    {
-	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
-			 fbGetCompositeClip(pGC));
-    }
-
-    /* Do bit blitting */
-    numRects = REGION_NUM_RECTS(&rgnDst);
-    if (numRects && widthSrc && heightSrc)
-	fbCopyRegion (pSrcDrawable, pDstDrawable, pGC,
-		      &rgnDst, dx, dy, copyProc, bitPlane, closure);
-
-    /* Pixmap sources generate a NoExposed (we return NULL to do this) */
-    if (!fastExpose && pGC->fExpose)
-	prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
-					xIn - pSrcDrawable->x,
-					yIn - pSrcDrawable->y,
-					widthSrc, heightSrc,
-					xOut - pDstDrawable->x,
-					yOut - pDstDrawable->y,
-					(unsigned long) bitPlane);
-    REGION_UNINIT(pGC->pScreen, &rgnDst);
-    if (freeSrcClip)
-	REGION_DESTROY(pGC->pScreen, prgnSrcClip);
-    fbValidateDrawable (pDstDrawable);
-    return prgnExposed;
-}
-
 RegionPtr
 fbCopyArea (DrawablePtr	pSrcDrawable,
 	    DrawablePtr	pDstDrawable,
@@ -623,7 +300,7 @@ fbCopyArea (DrawablePtr	pSrcDrawable,
 	    int		xOut, 
 	    int		yOut)
 {
-    fbCopyProc	copy;
+    miCopyProc	copy;
 
 #ifdef FB_24_32BIT
     if (pSrcDrawable->bitsPerPixel != pDstDrawable->bitsPerPixel)
@@ -631,7 +308,7 @@ fbCopyArea (DrawablePtr	pSrcDrawable,
     else
 #endif
 	copy = fbCopyNtoN;
-    return fbDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
+    return miDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
 		     widthSrc, heightSrc, xOut, yOut, copy, 0, 0);
 }
 
@@ -648,11 +325,11 @@ fbCopyPlane (DrawablePtr    pSrcDrawable,
 	     unsigned long  bitplane)
 {
     if (pSrcDrawable->bitsPerPixel > 1)
-	return fbDoCopy (pSrcDrawable, pDstDrawable, pGC,
+	return miDoCopy (pSrcDrawable, pDstDrawable, pGC,
 			 xIn, yIn, widthSrc, heightSrc,
 			 xOut, yOut, fbCopyNto1, (Pixel) bitplane, 0);
     else if (bitplane & 1)
-	return fbDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
+	return miDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
 			 widthSrc, heightSrc, xOut, yOut, fbCopy1toN,
 			 (Pixel) bitplane, 0);
     else
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 1432cb6..99939e8 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -248,7 +248,7 @@ fbOverlayCopyWindow(WindowPtr	pWin,
 	{
 	    REGION_TRANSLATE(pScreen, &layerRgn[i], -dx, -dy);
 	    pPixmap = pScrPriv->layer[i].u.run.pixmap;
-	    fbCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
+	    miCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
 			  0,
 			  &layerRgn[i], dx, dy, pScrPriv->CopyWindow, 0,
 			  (void *)(long) i);
diff --git a/fb/fboverlay.h b/fb/fboverlay.h
index ed355af..b626a77 100644
--- a/fb/fboverlay.h
+++ b/fb/fboverlay.h
@@ -53,7 +53,7 @@ typedef struct _fbOverlayLayer {
 typedef struct _fbOverlayScrPriv {
     int			    nlayers;
     fbOverlayPaintKeyProc   PaintKey;
-    fbCopyProc		    CopyWindow;
+    miCopyProc		    CopyWindow;
     FbOverlayLayer	    layer[FB_OVERLAY_MAX];
 } FbOverlayScrPrivRec, *FbOverlayScrPrivPtr;
 
diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index 022a16f..46c0334 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -140,7 +140,7 @@ fbCopyWindow(WindowPtr	    pWin,
 			  -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
 
-    fbCopyRegion (pDrawable, pDrawable,
+    miCopyRegion (pDrawable, pDrawable,
 		  0,
 		  &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
     
diff --git a/mi/Makefile.am b/mi/Makefile.am
index e6a4e60..979cc39 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -20,6 +20,7 @@ libmi_la_SOURCES = 	\
 	micmap.c	\
 	micmap.h	\
 	micoord.h	\
+	micopy.c	\
 	micursor.c	\
 	midash.c	\
 	midispcur.c	\
diff --git a/mi/mi.h b/mi/mi.h
index 23f9abb..c44ff06 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -56,6 +56,7 @@ SOFTWARE.
 #include "input.h"
 #include "cursor.h"
 #include "privates.h"
+#include "colormap.h"
 
 #define MiBits	CARD32
 
@@ -123,6 +124,47 @@ extern _X_EXPORT void miPutImage(
     char * /*pImage*/
 );
 
+/* micopy.c  */
+
+#define miGetCompositeClip(pGC) ((pGC)->pCompositeClip)
+
+typedef void	(*miCopyProc) (DrawablePtr  pSrcDrawable,
+			       DrawablePtr  pDstDrawable,
+			       GCPtr	    pGC,
+			       BoxPtr	    pDstBox,
+			       int	    nbox,
+			       int	    dx,
+			       int	    dy,
+			       Bool	    reverse,
+			       Bool	    upsidedown,
+			       Pixel	    bitplane,
+			       void	    *closure);
+
+extern _X_EXPORT void
+miCopyRegion (DrawablePtr   pSrcDrawable,
+	      DrawablePtr   pDstDrawable,
+	      GCPtr	    pGC,
+	      RegionPtr	    pDstRegion,
+	      int	    dx,
+	      int	    dy,
+	      miCopyProc    copyProc,
+	      Pixel	    bitPlane,
+	      void	    *closure);
+
+extern _X_EXPORT RegionPtr
+miDoCopy (DrawablePtr	pSrcDrawable,
+	  DrawablePtr	pDstDrawable,
+	  GCPtr		pGC,
+	  int		xIn, 
+	  int		yIn,
+	  int		widthSrc, 
+	  int		heightSrc,
+	  int		xOut, 
+	  int		yOut,
+	  miCopyProc	copyProc,
+	  Pixel		bitplane,
+	  void		*closure);
+
 /* micursor.c */
 
 extern _X_EXPORT void miRecolorCursor(
diff --git a/mi/micopy.c b/mi/micopy.c
new file mode 100644
index 0000000..3719f46
--- /dev/null
+++ b/mi/micopy.c
@@ -0,0 +1,354 @@
+/*
+ * Copyright © 1998 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "mi.h"
+#include "scrnintstr.h"
+#include "gcstruct.h"
+#include "pixmap.h"
+#include "pixmapstr.h"
+#include "windowstr.h"
+
+void
+miCopyRegion (DrawablePtr   pSrcDrawable,
+	      DrawablePtr   pDstDrawable,
+	      GCPtr	    pGC,
+	      RegionPtr	    pDstRegion,
+	      int	    dx,
+	      int	    dy,
+	      miCopyProc    copyProc,
+	      Pixel	    bitPlane,
+	      void	    *closure)
+{
+    int		careful;
+    Bool	reverse;
+    Bool	upsidedown;
+    BoxPtr	pbox;
+    int		nbox;
+    BoxPtr	pboxNew1, pboxNew2, pboxBase, pboxNext, pboxTmp;
+    
+    pbox = REGION_RECTS(pDstRegion);
+    nbox = REGION_NUM_RECTS(pDstRegion);
+    
+    /* XXX we have to err on the side of safety when both are windows,
+     * because we don't know if IncludeInferiors is being used.
+     */
+    careful = ((pSrcDrawable == pDstDrawable) ||
+	       ((pSrcDrawable->type == DRAWABLE_WINDOW) &&
+		(pDstDrawable->type == DRAWABLE_WINDOW)));
+
+    pboxNew1 = NULL;
+    pboxNew2 = NULL;
+    if (careful && dy < 0)
+    {
+	upsidedown = TRUE;
+
+	if (nbox > 1)
+	{
+	    /* keep ordering in each band, reverse order of bands */
+	    pboxNew1 = (BoxPtr)xalloc(sizeof(BoxRec) * nbox);
+	    if(!pboxNew1)
+		return;
+	    pboxBase = pboxNext = pbox+nbox-1;
+	    while (pboxBase >= pbox)
+	    {
+		while ((pboxNext >= pbox) &&
+		       (pboxBase->y1 == pboxNext->y1))
+		    pboxNext--;
+		pboxTmp = pboxNext+1;
+		while (pboxTmp <= pboxBase)
+		{
+		    *pboxNew1++ = *pboxTmp++;
+		}
+		pboxBase = pboxNext;
+	    }
+	    pboxNew1 -= nbox;
+	    pbox = pboxNew1;
+	}
+    }
+    else
+    {
+	/* walk source top to bottom */
+	upsidedown = FALSE;
+    }
+
+    if (careful && dx < 0)
+    {
+	/* walk source right to left */
+	if (dy <= 0)
+	    reverse = TRUE;
+	else
+	    reverse = FALSE;
+
+	if (nbox > 1)
+	{
+	    /* reverse order of rects in each band */
+	    pboxNew2 = (BoxPtr)xalloc(sizeof(BoxRec) * nbox);
+	    if(!pboxNew2)
+	    {
+		if (pboxNew1)
+		    xfree(pboxNew1);
+		return;
+	    }
+	    pboxBase = pboxNext = pbox;
+	    while (pboxBase < pbox+nbox)
+	    {
+		while ((pboxNext < pbox+nbox) &&
+		       (pboxNext->y1 == pboxBase->y1))
+		    pboxNext++;
+		pboxTmp = pboxNext;
+		while (pboxTmp != pboxBase)
+		{
+		    *pboxNew2++ = *--pboxTmp;
+		}
+		pboxBase = pboxNext;
+	    }
+	    pboxNew2 -= nbox;
+	    pbox = pboxNew2;
+	}
+    }
+    else
+    {
+	/* walk source left to right */
+	reverse = FALSE;
+    }
+
+    (*copyProc) (pSrcDrawable,
+		 pDstDrawable,
+		 pGC,
+		 pbox,
+		 nbox,
+		 dx, dy,
+		 reverse, upsidedown, bitPlane, closure);
+    
+    if (pboxNew1)
+	xfree (pboxNew1);
+    if (pboxNew2)
+	xfree (pboxNew2);
+}
+
+RegionPtr
+miDoCopy (DrawablePtr	pSrcDrawable,
+	  DrawablePtr	pDstDrawable,
+	  GCPtr		pGC,
+	  int		xIn, 
+	  int		yIn,
+	  int		widthSrc, 
+	  int		heightSrc,
+	  int		xOut, 
+	  int		yOut,
+	  miCopyProc	copyProc,
+	  Pixel		bitPlane,
+	  void		*closure)
+{
+    RegionPtr	prgnSrcClip = NULL; /* may be a new region, or just a copy */
+    Bool	freeSrcClip = FALSE;
+    RegionPtr	prgnExposed = NULL;
+    RegionRec	rgnDst;
+    int		dx;
+    int		dy;
+    int		numRects;
+    int         box_x1;
+    int         box_y1;
+    int         box_x2;
+    int         box_y2;
+    Bool	fastSrc = FALSE;    /* for fast clipping with pixmap source */
+    Bool	fastDst = FALSE;    /* for fast clipping with one rect dest */
+    Bool	fastExpose = FALSE; /* for fast exposures with pixmap source */
+
+    /* Short cut for unmapped windows */
+
+    if (pDstDrawable->type == DRAWABLE_WINDOW && 
+	!((WindowPtr)pDstDrawable)->realized)
+    {
+	return NULL;
+    }
+
+    if ((pSrcDrawable != pDstDrawable) &&
+	pSrcDrawable->pScreen->SourceValidate)
+    {
+	(*pSrcDrawable->pScreen->SourceValidate) (pSrcDrawable, xIn, yIn, widthSrc, heightSrc);
+    }
+
+    /* Compute source clip region */
+    if (pSrcDrawable->type == DRAWABLE_PIXMAP)
+    {
+	if ((pSrcDrawable == pDstDrawable) && (pGC->clientClipType == CT_NONE))
+	    prgnSrcClip = miGetCompositeClip(pGC);
+	else
+	    fastSrc = TRUE;
+    }
+    else
+    {
+	if (pGC->subWindowMode == IncludeInferiors)
+	{
+	    /*
+	     * XFree86 DDX empties the border clip when the
+	     * VT is inactive, make sure the region isn't empty
+	     */
+	    if (!((WindowPtr) pSrcDrawable)->parent &&
+		REGION_NOTEMPTY (pSrcDrawable->pScreen,
+				 &((WindowPtr) pSrcDrawable)->borderClip))
+	    {
+		/*
+		 * special case bitblt from root window in
+		 * IncludeInferiors mode; just like from a pixmap
+		 */
+		fastSrc = TRUE;
+	    }
+	    else if ((pSrcDrawable == pDstDrawable) &&
+		     (pGC->clientClipType == CT_NONE))
+	    {
+		prgnSrcClip = miGetCompositeClip(pGC);
+	    }
+	    else
+	    {
+		prgnSrcClip = NotClippedByChildren((WindowPtr)pSrcDrawable);
+		freeSrcClip = TRUE;
+	    }
+	}
+	else
+	{
+	    prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList;
+	}
+    }
+
+    xIn += pSrcDrawable->x;
+    yIn += pSrcDrawable->y;
+    
+    xOut += pDstDrawable->x;
+    yOut += pDstDrawable->y;
+
+    box_x1 = xIn;
+    box_y1 = yIn;
+    box_x2 = xIn + widthSrc;
+    box_y2 = yIn + heightSrc;
+
+    dx = xIn - xOut;
+    dy = yIn - yOut;
+
+    /* Don't create a source region if we are doing a fast clip */
+    if (fastSrc)
+    {
+	RegionPtr cclip;
+    
+	fastExpose = TRUE;
+	/*
+	 * clip the source; if regions extend beyond the source size,
+ 	 * make sure exposure events get sent
+	 */
+	if (box_x1 < pSrcDrawable->x)
+	{
+	    box_x1 = pSrcDrawable->x;
+	    fastExpose = FALSE;
+	}
+	if (box_y1 < pSrcDrawable->y)
+	{
+	    box_y1 = pSrcDrawable->y;
+	    fastExpose = FALSE;
+	}
+	if (box_x2 > pSrcDrawable->x + (int) pSrcDrawable->width)
+	{
+	    box_x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
+	    fastExpose = FALSE;
+	}
+	if (box_y2 > pSrcDrawable->y + (int) pSrcDrawable->height)
+	{
+	    box_y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
+	    fastExpose = FALSE;
+	}
+	
+	/* Translate and clip the dst to the destination composite clip */
+        box_x1 -= dx;
+        box_x2 -= dx;
+        box_y1 -= dy;
+        box_y2 -= dy;
+
+	/* If the destination composite clip is one rectangle we can
+	   do the clip directly.  Otherwise we have to create a full
+	   blown region and call intersect */
+
+	cclip = miGetCompositeClip(pGC);
+        if (REGION_NUM_RECTS(cclip) == 1)
+        {
+	    BoxPtr pBox = REGION_RECTS(cclip);
+
+	    if (box_x1 < pBox->x1) box_x1 = pBox->x1;
+	    if (box_x2 > pBox->x2) box_x2 = pBox->x2;
+	    if (box_y1 < pBox->y1) box_y1 = pBox->y1;
+	    if (box_y2 > pBox->y2) box_y2 = pBox->y2;
+	    fastDst = TRUE;
+	}
+    }
+    
+    /* Check to see if the region is empty */
+    if (box_x1 >= box_x2 || box_y1 >= box_y2)
+    {
+	REGION_NULL(pGC->pScreen, &rgnDst);
+    }
+    else
+    {
+        BoxRec	box;
+	box.x1 = box_x1;
+	box.y1 = box_y1;
+	box.x2 = box_x2;
+	box.y2 = box_y2;
+	REGION_INIT(pGC->pScreen, &rgnDst, &box, 1);
+    }
+    
+    /* Clip against complex source if needed */
+    if (!fastSrc)
+    {
+	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip);
+	REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy);
+    }
+
+    /* Clip against complex dest if needed */
+    if (!fastDst)
+    {
+	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
+			 miGetCompositeClip(pGC));
+    }
+
+    /* Do bit blitting */
+    numRects = REGION_NUM_RECTS(&rgnDst);
+    if (numRects && widthSrc && heightSrc)
+	miCopyRegion (pSrcDrawable, pDstDrawable, pGC,
+		      &rgnDst, dx, dy, copyProc, bitPlane, closure);
+
+    /* Pixmap sources generate a NoExposed (we return NULL to do this) */
+    if (!fastExpose && pGC->fExpose)
+	prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
+					xIn - pSrcDrawable->x,
+					yIn - pSrcDrawable->y,
+					widthSrc, heightSrc,
+					xOut - pDstDrawable->x,
+					yOut - pDstDrawable->y,
+					(unsigned long) bitPlane);
+    REGION_UNINIT(pGC->pScreen, &rgnDst);
+    if (freeSrcClip)
+	REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+    return prgnExposed;
+}
commit f06bde3d4bf9a0f245dfa6c65cd98f8e0c7dfdfc
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Sat Jan 31 19:57:07 2009 +0100

    exa: create ExaCheckGetImage

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 10e7914..02858f1 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -1201,12 +1201,7 @@ exaGetImage (DrawablePtr pDrawable, int x, int y, int w, int h,
     }
 
 fallback:
-    EXA_FALLBACK(("from %p (%c)\n", pDrawable,
-		  exaDrawableLocation(pDrawable)));
-
-    exaPrepareAccessReg (pDrawable, EXA_PREPARE_SRC, &Reg);
-    fbGetImage (pDrawable, x, y, w, h, format, planeMask, d);
-    exaFinishAccess (pDrawable, EXA_PREPARE_SRC);
+    ExaCheckGetImage(pDrawable, x, y, w, h, format, planeMask, d);
 
 out:
     REGION_UNINIT(pScreen, &Reg);
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index a41e5fe..6d7c1dd 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -361,6 +361,10 @@ ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
 		   int w, int h, int x, int y);
 
 void
+ExaCheckGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
+		unsigned int format, unsigned long planeMask, char *d);
+
+void
 ExaCheckGetSpans (DrawablePtr pDrawable,
 		 int wMax,
 		 DDXPointPtr ppt,
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index a521497..e0f2ae9 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -283,6 +283,36 @@ ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
 }
 
 void
+ExaCheckGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
+		unsigned int format, unsigned long planeMask, char *d)
+{
+    BoxRec Box;
+    RegionRec Reg;
+    int xoff, yoff;
+    ScreenPtr pScreen = pDrawable->pScreen;
+    PixmapPtr pPix = exaGetDrawablePixmap (pDrawable);
+    ExaScreenPriv(pScreen);
+
+    EXA_FALLBACK(("from %p (%c)\n", pDrawable,
+		  exaDrawableLocation(pDrawable)));
+
+    exaGetDrawableDeltas(pDrawable, pPix, &xoff, &yoff);
+
+    Box.x1 = pDrawable->y + x + xoff;
+    Box.y1 = pDrawable->y + y + yoff;
+    Box.x2 = Box.x1 + w;
+    Box.y2 = Box.y1 + h;
+
+    REGION_INIT(pScreen, &Reg, &Box, 1);
+
+    exaPrepareAccessReg (pDrawable, EXA_PREPARE_SRC, &Reg);
+    swap(pExaScr, pScreen, GetImage);
+    pScreen->GetImage (pDrawable, x, y, w, h, format, planeMask, d);
+    swap(pExaScr, pScreen, GetImage);
+    exaFinishAccess (pDrawable, EXA_PREPARE_SRC);
+}
+
+void
 ExaCheckGetSpans (DrawablePtr pDrawable,
 		 int wMax,
 		 DDXPointPtr ppt,
commit 258fc4b106dfd7b583999f97caf4d4a7a11569b6
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Sat Jan 31 19:40:48 2009 +0100

    exa: wrap the remainder of exa_unaccel.c

diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index d56f589..a521497 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -290,9 +290,14 @@ ExaCheckGetSpans (DrawablePtr pDrawable,
 		 int nspans,
 		 char *pdstStart)
 {
+    ScreenPtr pScreen = pDrawable->pScreen;
+    ExaScreenPriv(pScreen);
+
     EXA_FALLBACK(("from %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
     exaPrepareAccess (pDrawable, EXA_PREPARE_SRC);
-    fbGetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+    swap(pExaScr, pScreen, GetSpans);
+    pScreen->GetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+    swap(pExaScr, pScreen, GetSpans);
     exaFinishAccess (pDrawable, EXA_PREPARE_SRC);
 }
 
@@ -310,6 +315,11 @@ ExaCheckComposite (CARD8      op,
                    CARD16     width,
                    CARD16     height)
 {
+    ScreenPtr pScreen = pDst->pDrawable->pScreen;
+#ifdef RENDER
+    PictureScreenPtr	ps = GetPictureScreen(pScreen);
+#endif /* RENDER */
+    ExaScreenPriv(pScreen);
     RegionRec region;
     int xoff, yoff;
 
@@ -338,7 +348,9 @@ ExaCheckComposite (CARD8      op,
 	exaPrepareAccess (pSrc->pDrawable, EXA_PREPARE_SRC);
     if (pMask && pMask->pDrawable != NULL)
 	exaPrepareAccess (pMask->pDrawable, EXA_PREPARE_MASK);
-    fbComposite (op,
+#ifdef RENDER
+    swap(pExaScr, ps, Composite);
+    ps->Composite (op,
                  pSrc,
                  pMask,
                  pDst,
@@ -350,6 +362,8 @@ ExaCheckComposite (CARD8      op,
                  yDst,
                  width,
                  height);
+    swap(pExaScr, ps, Composite);
+#endif /* RENDER */
     if (pMask && pMask->pDrawable != NULL)
 	exaFinishAccess (pMask->pDrawable, EXA_PREPARE_MASK);
     if (pSrc->pDrawable != NULL)
@@ -366,10 +380,20 @@ ExaCheckAddTraps (PicturePtr	pPicture,
 		  int		ntrap,
 		  xTrap		*traps)
 {
+    ScreenPtr pScreen = pPicture->pDrawable->pScreen;
+#ifdef RENDER
+    PictureScreenPtr	ps = GetPictureScreen(pScreen);
+#endif /* RENDER */
+    ExaScreenPriv(pScreen);
+
     EXA_FALLBACK(("to pict %p (%c)\n",
 		  exaDrawableLocation(pPicture->pDrawable)));
     exaPrepareAccess(pPicture->pDrawable, EXA_PREPARE_DEST);
-    fbAddTraps (pPicture, x_off, y_off, ntrap, traps);
+#ifdef RENDER
+    swap(pExaScr, ps, AddTraps);
+    ps->AddTraps (pPicture, x_off, y_off, ntrap, traps);
+    swap(pExaScr, ps, AddTraps);
+#endif /* RENDER */
     exaFinishAccess(pPicture->pDrawable, EXA_PREPARE_DEST);
 }
 
commit 6fabf249494bf38b69e3c9c6c9718ee8b12fc6e1
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Sat Jan 31 19:25:20 2009 +0100

    exa: use proper wrapping in exa.c

diff --git a/exa/exa.c b/exa/exa.c
index 58d1a7d..033b353 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -188,6 +188,7 @@ exaDestroyPixmap (PixmapPtr pPixmap)
 {
     ScreenPtr	pScreen = pPixmap->drawable.pScreen;
     ExaScreenPriv(pScreen);
+    Bool ret;
 
     if (pPixmap->refcnt == 1)
     {
@@ -213,7 +214,12 @@ exaDestroyPixmap (PixmapPtr pPixmap)
 	REGION_UNINIT(pPixmap->drawable.pScreen, &pExaPixmap->validSys);
 	REGION_UNINIT(pPixmap->drawable.pScreen, &pExaPixmap->validFB);
     }
-    return fbDestroyPixmap (pPixmap);
+
+    swap(pExaScr, pScreen, DestroyPixmap);
+    ret = pScreen->DestroyPixmap (pPixmap);
+    swap(pExaScr, pScreen, DestroyPixmap);
+
+    return ret;
 }
 
 static int
@@ -286,12 +292,14 @@ exaCreatePixmap(ScreenPtr pScreen, int w, int h, int depth,
     if (w > 32767 || h > 32767)
 	return NullPixmap;
 
+    swap(pExaScr, pScreen, CreatePixmap);
     if (!pExaScr->info->CreatePixmap) {
-        pPixmap = fbCreatePixmap (pScreen, w, h, depth, usage_hint);
+        pPixmap = pScreen->CreatePixmap (pScreen, w, h, depth, usage_hint);
     } else {
         driver_alloc = 1;
-        pPixmap = fbCreatePixmap(pScreen, 0, 0, depth, usage_hint);
+        pPixmap = pScreen->CreatePixmap(pScreen, 0, 0, depth, usage_hint);
     }
+    swap(pExaScr, pScreen, CreatePixmap);
 
     if (!pPixmap)
         return NULL;
@@ -322,8 +330,10 @@ exaCreatePixmap(ScreenPtr pScreen, int w, int h, int depth,
 
         pExaPixmap->driverPriv = pExaScr->info->CreatePixmap(pScreen, datasize, 0);
         if (!pExaPixmap->driverPriv) {
-             fbDestroyPixmap(pPixmap);
-             return NULL;
+	    swap(pExaScr, pScreen, DestroyPixmap);
+	    pScreen->DestroyPixmap (pPixmap);
+	    swap(pExaScr, pScreen, DestroyPixmap);
+	    return NULL;
         }
 
         (*pScreen->ModifyPixmapHeader)(pPixmap, w, h, 0, 0,
@@ -354,8 +364,10 @@ exaCreatePixmap(ScreenPtr pScreen, int w, int h, int depth,
         pExaPixmap->fb_size = pExaPixmap->fb_pitch * h;
 
         if (pExaPixmap->fb_pitch > 131071) {
-	     fbDestroyPixmap(pPixmap);
-	     return NULL;
+	    swap(pExaScr, pScreen, DestroyPixmap);
+	    pScreen->DestroyPixmap (pPixmap);
+	    swap(pExaScr, pScreen, DestroyPixmap);
+	    return NULL;
         }
 
 	/* Set up damage tracking */
@@ -364,7 +376,9 @@ exaCreatePixmap(ScreenPtr pScreen, int w, int h, int depth,
 					    pScreen, pPixmap);
 
 	if (pExaPixmap->pDamage == NULL) {
-	    fbDestroyPixmap (pPixmap);
+	    swap(pExaScr, pScreen, DestroyPixmap);
+	    pScreen->DestroyPixmap (pPixmap);
+	    swap(pExaScr, pScreen, DestroyPixmap);
 	    return NULL;
 	}
 
@@ -774,6 +788,8 @@ static Bool
 exaChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
 {
     Bool ret;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    ExaScreenPriv(pScreen);
 
     if ((mask & CWBackPixmap) && pWin->backgroundState == BackgroundPixmap) 
         exaPrepareAccess(&pWin->background.pixmap->drawable, EXA_PREPARE_SRC);
@@ -781,7 +797,9 @@ exaChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
     if ((mask & CWBorderPixmap) && pWin->borderIsPixel == FALSE)
         exaPrepareAccess(&pWin->border.pixmap->drawable, EXA_PREPARE_MASK);
 
-    ret = fbChangeWindowAttributes(pWin, mask);
+    swap(pExaScr, pScreen, ChangeWindowAttributes);
+    ret = pScreen->ChangeWindowAttributes(pWin, mask);
+    swap(pExaScr, pScreen, ChangeWindowAttributes);
 
     if ((mask & CWBorderPixmap) && pWin->borderIsPixel == FALSE)
         exaFinishAccess(&pWin->border.pixmap->drawable, EXA_PREPARE_MASK);
@@ -796,9 +814,15 @@ static RegionPtr
 exaBitmapToRegion(PixmapPtr pPix)
 {
     RegionPtr ret;
+    ScreenPtr pScreen = pPix->drawable.pScreen;
+    ExaScreenPriv(pScreen);
+
     exaPrepareAccess(&pPix->drawable, EXA_PREPARE_SRC);
-    ret = fbPixmapToRegion(pPix);
+    swap(pExaScr, pScreen, BitmapToRegion);
+    ret = pScreen->BitmapToRegion(pPix);
+    swap(pExaScr, pScreen, BitmapToRegion);
     exaFinishAccess(&pPix->drawable, EXA_PREPARE_SRC);
+
     return ret;
 }
 
@@ -809,9 +833,9 @@ exaCreateScreenResources(ScreenPtr pScreen)
     PixmapPtr pScreenPixmap;
     Bool b;
 
-    pScreen->CreateScreenResources = pExaScr->SavedCreateScreenResources;
+    swap(pExaScr, pScreen, CreateScreenResources);
     b = pScreen->CreateScreenResources(pScreen);
-    pScreen->CreateScreenResources = exaCreateScreenResources;
+    swap(pExaScr, pScreen, CreateScreenResources);
 
     if (!b)
         return FALSE;
@@ -845,23 +869,26 @@ exaCloseScreen(int i, ScreenPtr pScreen)
     if (ps->Glyphs == exaGlyphs)
 	exaGlyphsFini(pScreen);
 
-    pScreen->CreateGC = pExaScr->SavedCreateGC;
-    pScreen->CloseScreen = pExaScr->SavedCloseScreen;
-    pScreen->GetImage = pExaScr->SavedGetImage;
-    pScreen->GetSpans = pExaScr->SavedGetSpans;
-    pScreen->CreatePixmap = pExaScr->SavedCreatePixmap;
-    pScreen->DestroyPixmap = pExaScr->SavedDestroyPixmap;
-    pScreen->CopyWindow = pExaScr->SavedCopyWindow;
-    pScreen->ChangeWindowAttributes = pExaScr->SavedChangeWindowAttributes;
-    pScreen->BitmapToRegion = pExaScr->SavedBitmapToRegion;
-    pScreen->CreateScreenResources = pExaScr->SavedCreateScreenResources;
+    unwrap(pExaScr, pScreen, CreateGC);
+    unwrap(pExaScr, pScreen, CloseScreen);
+    unwrap(pExaScr, pScreen, GetImage);
+    unwrap(pExaScr, pScreen, GetSpans);
+    if (pExaScr->SavedCreatePixmap)
+	unwrap(pExaScr, pScreen, CreatePixmap);
+    if (pExaScr->SavedDestroyPixmap)
+	unwrap(pExaScr, pScreen, DestroyPixmap);
+    unwrap(pExaScr, pScreen, CopyWindow);
+    unwrap(pExaScr, pScreen, ChangeWindowAttributes);
+    unwrap(pExaScr, pScreen, BitmapToRegion);
+    unwrap(pExaScr, pScreen, CreateScreenResources);
 #ifdef RENDER
     if (ps) {
-	ps->Composite = pExaScr->SavedComposite;
-	ps->Glyphs = pExaScr->SavedGlyphs;
-	ps->Trapezoids = pExaScr->SavedTrapezoids;
-	ps->Triangles = pExaScr->SavedTriangles;
-	ps->AddTraps = pExaScr->SavedAddTraps;
+	unwrap(pExaScr, ps, Composite);
+	if (pExaScr->SavedGlyphs)
+	    unwrap(pExaScr, ps, Glyphs);
+	unwrap(pExaScr, ps, Trapezoids);
+	unwrap(pExaScr, ps, Triangles);
+	unwrap(pExaScr, ps, AddTraps);
     }
 #endif
 
@@ -1001,48 +1028,23 @@ exaDriverInit (ScreenPtr		pScreen,
     /*
      * Replace various fb screen functions
      */
-    pExaScr->SavedCloseScreen = pScreen->CloseScreen;
-    pScreen->CloseScreen = exaCloseScreen;
-
-    pExaScr->SavedCreateGC = pScreen->CreateGC;
-    pScreen->CreateGC = exaCreateGC;
-
-    pExaScr->SavedGetImage = pScreen->GetImage;
-    pScreen->GetImage = exaGetImage;
-
-    pExaScr->SavedGetSpans = pScreen->GetSpans;
-    pScreen->GetSpans = ExaCheckGetSpans;
-
-    pExaScr->SavedCopyWindow = pScreen->CopyWindow;
-    pScreen->CopyWindow = exaCopyWindow;
-
-    pExaScr->SavedChangeWindowAttributes = pScreen->ChangeWindowAttributes;
-    pScreen->ChangeWindowAttributes = exaChangeWindowAttributes;
-
-    pExaScr->SavedBitmapToRegion = pScreen->BitmapToRegion;
-    pScreen->BitmapToRegion = exaBitmapToRegion;
-
-    pExaScr->SavedCreateScreenResources = pScreen->CreateScreenResources;
-    pScreen->CreateScreenResources = exaCreateScreenResources;
+    wrap(pExaScr, pScreen, CreateGC, exaCreateGC);
+    wrap(pExaScr, pScreen, CloseScreen, exaCloseScreen);
+    wrap(pExaScr, pScreen, GetImage, exaGetImage);
+    wrap(pExaScr, pScreen, GetSpans, ExaCheckGetSpans);
+    wrap(pExaScr, pScreen, CopyWindow, exaCopyWindow);
+    wrap(pExaScr, pScreen, ChangeWindowAttributes, exaChangeWindowAttributes);
+    wrap(pExaScr, pScreen, BitmapToRegion, exaBitmapToRegion);
+    wrap(pExaScr, pScreen, CreateScreenResources, exaCreateScreenResources);
 
 #ifdef RENDER
     if (ps) {
-        pExaScr->SavedComposite = ps->Composite;
-	ps->Composite = exaComposite;
-
-	if (pScreenInfo->PrepareComposite) {
-	    pExaScr->SavedGlyphs = ps->Glyphs;
-	    ps->Glyphs = exaGlyphs;
-	}
-	
-	pExaScr->SavedTriangles = ps->Triangles;
-	ps->Triangles = exaTriangles;
-
-	pExaScr->SavedTrapezoids = ps->Trapezoids;
-	ps->Trapezoids = exaTrapezoids;
-
-	pExaScr->SavedAddTraps = ps->AddTraps;
-	ps->AddTraps = ExaCheckAddTraps;
+	wrap(pExaScr, ps, Composite, exaComposite);
+	if (pScreenInfo->PrepareComposite)
+	    wrap(pExaScr, ps, Glyphs, exaGlyphs);
+	wrap(pExaScr, ps, Trapezoids, exaTrapezoids);
+	wrap(pExaScr, ps, Triangles, exaTriangles);
+	wrap(pExaScr, ps, AddTraps, ExaCheckAddTraps);
     }
 #endif
 
@@ -1063,11 +1065,8 @@ exaDriverInit (ScreenPtr		pScreen,
 		       pScreen->myNum);
 	    return FALSE;
         }
-        pExaScr->SavedCreatePixmap = pScreen->CreatePixmap;
-	pScreen->CreatePixmap = exaCreatePixmap;
-
-        pExaScr->SavedDestroyPixmap = pScreen->DestroyPixmap;
-	pScreen->DestroyPixmap = exaDestroyPixmap;
+	wrap(pExaScr, pScreen, CreatePixmap, exaCreatePixmap);
+	wrap(pExaScr, pScreen, DestroyPixmap, exaDestroyPixmap);
 
 	pExaScr->SavedModifyPixmapHeader = pScreen->ModifyPixmapHeader;
 	pScreen->ModifyPixmapHeader = exaModifyPixmapHeader;
commit 015c99a4ad572f5a1b68054efb070e1ffee1fed0
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Sat Jan 31 18:53:52 2009 +0100

    exa: properly wrap GC functions

diff --git a/exa/exa.c b/exa/exa.c
index 496b898..58d1a7d 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -575,86 +575,178 @@ exaFinishAccess(DrawablePtr pDrawable, int index)
 }
 
 /**
- * exaValidateGC() sets the ops to EXA's implementations, which may be
- * accelerated or may sync the card and fall back to fb.
+ * Here begins EXA's GC code.
+ * Do not ever access the fb/mi layer directly.
  */
+
+static void
+exaValidateGC(GCPtr pGC,
+		unsigned long changes,
+		DrawablePtr pDrawable);
+
+static void
+exaDestroyGC(GCPtr pGC);
+
+static void
+exaChangeGC (GCPtr pGC,
+		unsigned long mask);
+
+static void
+exaCopyGC (GCPtr pGCSrc,
+	      unsigned long mask,
+	      GCPtr	 pGCDst);
+
+static void
+exaChangeClip (GCPtr pGC,
+		int type,
+		pointer pvalue,
+		int nrects);
+
 static void
-exaValidateGC (GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
+exaCopyClip(GCPtr pGCDst, GCPtr pGCSrc);
+
+static void
+exaCopyClip(GCPtr pGCDst, GCPtr pGCSrc);
+
+static void
+exaDestroyClip(GCPtr pGC);
+
+const GCFuncs exaGCFuncs = {
+    exaValidateGC,
+    exaChangeGC,
+    exaCopyGC,
+    exaDestroyGC,
+    exaChangeClip,
+    exaDestroyClip,
+    exaCopyClip
+};
+
+/*
+ * This wrapper exists to allow fbValidateGC to work.
+ */
+static PixmapPtr
+exaCreatePixmapWithPrepare(ScreenPtr pScreen, int w, int h, int depth,
+		unsigned usage_hint)
+{
+    PixmapPtr pPixmap;
+    ExaScreenPriv(pScreen);
+
+    /* This swaps between this function and the real upper layer function.
+     * Normally this would swap to the fb layer pointer, this is a very special case.
+     */
+    swap(pExaScr, pScreen, CreatePixmap);
+    pPixmap = pScreen->CreatePixmap(pScreen, w, h, depth, usage_hint);
+    swap(pExaScr, pScreen, CreatePixmap);
+
+    if (!pPixmap)
+	return NULL;
+
+    /* We use MASK, because SRC is already taken. */
+    exaPrepareAccess(&pPixmap->drawable, EXA_PREPARE_MASK);
+
+    return pPixmap;
+}
+
+static void
+exaValidateGC(GCPtr pGC,
+		unsigned long changes,
+		DrawablePtr pDrawable)
 {
     /* fbValidateGC will do direct access to pixmaps if the tiling has changed.
-     * Preempt fbValidateGC by doing its work and masking the change out, so
-     * that we can do the Prepare/FinishAccess.
+     * Do a few smart things so fbValidateGC can do it's work.
      */
-#ifdef FB_24_32BIT
-    if ((changes & GCTile) && fbGetRotatedPixmap(pGC)) {
-	(*pGC->pScreen->DestroyPixmap) (fbGetRotatedPixmap(pGC));
-	fbGetRotatedPixmap(pGC) = 0;
-    }
-	
-    if (pGC->fillStyle == FillTiled) {
-	PixmapPtr	pOldTile, pNewTile;
 
-	pOldTile = pGC->tile.pixmap;
-	if (pOldTile->drawable.bitsPerPixel != pDrawable->bitsPerPixel)
-	{
-	    pNewTile = fbGetRotatedPixmap(pGC);
-	    if (!pNewTile ||
-		pNewTile ->drawable.bitsPerPixel != pDrawable->bitsPerPixel)
-	    {
-		if (pNewTile)
-		    (*pGC->pScreen->DestroyPixmap) (pNewTile);
-		/* fb24_32ReformatTile will do direct access of a newly-
-		 * allocated pixmap.  This isn't a problem yet, since we don't
-		 * put pixmaps in FB until at least one accelerated EXA op.
-		 */
-		exaPrepareAccess(&pOldTile->drawable, EXA_PREPARE_SRC);
-		pNewTile = fb24_32ReformatTile (pOldTile,
-						pDrawable->bitsPerPixel);
-		exaPixmapDirty(pNewTile, 0, 0, pNewTile->drawable.width, pNewTile->drawable.height);
-		exaFinishAccess(&pOldTile->drawable, EXA_PREPARE_SRC);
-	    }
-	    if (pNewTile)
-	    {
-		fbGetRotatedPixmap(pGC) = pOldTile;
-		pGC->tile.pixmap = pNewTile;
-		changes |= GCTile;
-	    }
-	}
+    ScreenPtr pScreen = pDrawable->pScreen;
+    ExaScreenPriv(pScreen);
+    CreatePixmapProcPtr old_ptr = NULL;
+    PixmapPtr pTile = NULL;
+    EXA_GC_PROLOGUE(pGC);
+    if (changes & GCTile) {
+	/* save the "fb" pointer. */
+	old_ptr = pExaScr->SavedCreatePixmap;
+	/* create a new upper layer pointer. */
+	wrap(pExaScr, pScreen, CreatePixmap, exaCreatePixmapWithPrepare);
+	if (pGC->fillStyle == FillTiled)
+		pTile = pGC->tile.pixmap;
+	if (pTile)
+	    exaPrepareAccess(&pTile->drawable, EXA_PREPARE_SRC);
     }
-#endif
+    exaPrepareAccessGC(pGC);
+    (*pGC->funcs->ValidateGC)(pGC, changes, pDrawable);
+    exaFinishAccessGC(pGC);
     if (changes & GCTile) {
-	if (!pGC->tileIsPixel && FbEvenTile (pGC->tile.pixmap->drawable.width *
-					     pDrawable->bitsPerPixel))
-	{
-	    exaPrepareAccess(&pGC->tile.pixmap->drawable, EXA_PREPARE_SRC);
-	    fbPadPixmap (pGC->tile.pixmap);
-	    exaFinishAccess(&pGC->tile.pixmap->drawable, EXA_PREPARE_SRC);
+	/* switch back to the normal upper layer. */
+	unwrap(pExaScr, pScreen, CreatePixmap);
+	/* restore copy of fb layer pointer. */
+	pExaScr->SavedCreatePixmap = old_ptr;
+	if (pTile)
+	    exaFinishAccess(&pTile->drawable, EXA_PREPARE_SRC);
+
+	/* A new tile pixmap was created. */
+	if (pGC->tile.pixmap != pTile && pGC->fillStyle == FillTiled) {
+	    exaFinishAccess(&pGC->tile.pixmap->drawable, EXA_PREPARE_MASK);
 	    exaPixmapDirty(pGC->tile.pixmap, 0, 0,
 			   pGC->tile.pixmap->drawable.width,
 			   pGC->tile.pixmap->drawable.height);
 	}
-	/* Mask out the GCTile change notification, now that we've done FB's
-	 * job for it.
-	 */
-	changes &= ~GCTile;
     }
+    EXA_GC_EPILOGUE(pGC);
+}
 
-    exaPrepareAccessGC(pGC);
-    fbValidateGC (pGC, changes, pDrawable);
-    exaFinishAccessGC(pGC);
+/* Is exaPrepareAccessGC() needed? */
+static void
+exaDestroyGC(GCPtr pGC)
+{
+    EXA_GC_PROLOGUE (pGC);
+    (*pGC->funcs->DestroyGC)(pGC);
+    EXA_GC_EPILOGUE (pGC);
+}
 
-    pGC->ops = (GCOps *) &exaOps;
+static void
+exaChangeGC (GCPtr pGC,
+		unsigned long mask)
+{
+    EXA_GC_PROLOGUE (pGC);
+    (*pGC->funcs->ChangeGC) (pGC, mask);
+    EXA_GC_EPILOGUE (pGC);
 }
 
-static GCFuncs	exaGCFuncs = {
-    exaValidateGC,
-    miChangeGC,
-    miCopyGC,
-    miDestroyGC,
-    miChangeClip,
-    miDestroyClip,
-    miCopyClip
-};
+static void
+exaCopyGC (GCPtr pGCSrc,
+	      unsigned long mask,
+	      GCPtr	 pGCDst)
+{
+    EXA_GC_PROLOGUE (pGCDst);
+    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
+    EXA_GC_EPILOGUE (pGCDst);
+}
+
+static void
+exaChangeClip (GCPtr pGC,
+		int type,
+		pointer pvalue,
+		int nrects)
+{
+    EXA_GC_PROLOGUE (pGC);
+    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
+    EXA_GC_EPILOGUE (pGC);
+}
+
+static void
+exaCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
+{
+    EXA_GC_PROLOGUE (pGCDst);
+    (*pGCDst->funcs->CopyClip)(pGCDst, pGCSrc);
+    EXA_GC_EPILOGUE (pGCDst);
+}
+
+static void
+exaDestroyClip(GCPtr pGC)
+{
+    EXA_GC_PROLOGUE (pGC);
+    (*pGC->funcs->DestroyClip)(pGC);
+    EXA_GC_EPILOGUE (pGC);
+}
 
 /**
  * exaCreateGC makes a new GC and hooks up its funcs handler, so that
@@ -663,14 +755,19 @@ static GCFuncs	exaGCFuncs = {
 static int
 exaCreateGC (GCPtr pGC)
 {
+    ScreenPtr pScreen = pGC->pScreen;
+    ExaScreenPriv(pScreen);
     ExaGCPriv(pGC);
+    Bool ret;
 
-    if (!fbCreateGC (pGC))
-	return FALSE;
-
-    pGC->funcs = &exaGCFuncs;
+    swap(pExaScr, pScreen, CreateGC);
+    if ((ret = (*pScreen->CreateGC) (pGC))) {
+	wrap(pExaGC, pGC, funcs, (GCFuncs *) &exaGCFuncs);
+	wrap(pExaGC, pGC, ops, (GCOps *) &exaOps);
+    }
+    swap(pExaScr, pScreen, CreateGC);
 
-    return TRUE;
+    return ret;
 }
 
 static Bool
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 3b58948..a41e5fe 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -180,6 +180,33 @@ extern DevPrivateKey exaGCPrivateKey;
 #define ExaGetGCPriv(gc) ((ExaGCPrivPtr)dixLookupPrivate(&(gc)->devPrivates, exaGCPrivateKey))
 #define ExaGCPriv(gc) ExaGCPrivPtr pExaGC = ExaGetGCPriv(gc)
 
+/*
+ * Some macros to deal with function wrapping.
+ */
+#define wrap(priv, real, mem, func) {\
+    priv->Saved##mem = real->mem; \
+    real->mem = func; \
+}
+
+#define unwrap(priv, real, mem) {\
+    real->mem = priv->Saved##mem; \
+}
+
+#define swap(priv, real, mem) {\
+    void *tmp = priv->Saved##mem; \
+    priv->Saved##mem = real->mem; \
+    real->mem = tmp; \
+}
+
+#define EXA_GC_PROLOGUE(_gc_) \
+    ExaGCPriv(_gc_); \
+    swap(pExaGC, _gc_, funcs); \
+    swap(pExaGC, _gc_, ops);
+
+#define EXA_GC_EPILOGUE(_gc_) \
+    swap(pExaGC, _gc_, funcs); \
+    swap(pExaGC, _gc_, ops);
+
 /** Align an offset to an arbitrary alignment */
 #define EXA_ALIGN(offset, align) (((offset) + (align) - 1) - \
 	(((offset) + (align) - 1) % (align)))
@@ -243,8 +270,8 @@ typedef struct {
 
 typedef struct {
     /* GC values from the layer below. */
-    GCOps *ops;
-    GCFuncs *funcs;
+    GCOps *Savedops;
+    GCFuncs *Savedfuncs;
 } ExaGCPrivRec, *ExaGCPrivPtr;
 
 typedef struct _ExaMigrationRec {
@@ -447,6 +474,8 @@ exaCopyNtoN (DrawablePtr    pSrcDrawable,
 	     Pixel	    bitplane,
 	     void	    *closure);
 
+extern const GCFuncs exaGCFuncs;
+
 /* exa_render.c */
 Bool
 exaOpReadsDestination (CARD8 op);
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index c030486..d56f589 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -74,22 +74,26 @@ void
 ExaCheckFillSpans (DrawablePtr pDrawable, GCPtr pGC, int nspans,
 		   DDXPointPtr ppt, int *pwidth, int fSorted)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
     exaPrepareAccessGC (pGC);
-    fbFillSpans (pDrawable, pGC, nspans, ppt, pwidth, fSorted);
+    pGC->ops->FillSpans (pDrawable, pGC, nspans, ppt, pwidth, fSorted);
     exaFinishAccessGC (pGC);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
 ExaCheckSetSpans (DrawablePtr pDrawable, GCPtr pGC, char *psrc,
 		 DDXPointPtr ppt, int *pwidth, int nspans, int fSorted)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
-    fbSetSpans (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
+    pGC->ops->SetSpans (pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
@@ -99,6 +103,7 @@ ExaCheckPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth,
 {
     ExaPixmapPriv(exaGetDrawablePixmap(pDrawable));
 
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
     if (exaGCReadsDestination(pDrawable, pGC->planemask, pGC->fillStyle,
 			      pGC->alu))
@@ -106,8 +111,9 @@ ExaCheckPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth,
     else
 	exaPrepareAccessReg (pDrawable, EXA_PREPARE_DEST, pExaPixmap->pDamage ?
 			     DamagePendingRegion(pExaPixmap->pDamage) : NULL);
-    fbPutImage (pDrawable, pGC, depth, x, y, w, h, leftPad, format, bits);
+    pGC->ops->PutImage (pDrawable, pGC, depth, x, y, w, h, leftPad, format, bits);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 RegionPtr
@@ -116,13 +122,15 @@ ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 {
     RegionPtr ret;
 
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrc, pDst,
 		  exaDrawableLocation(pSrc), exaDrawableLocation(pDst)));
     exaPrepareAccess (pDst, EXA_PREPARE_DEST);
     exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
-    ret = fbCopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
+    ret = pGC->ops->CopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
     exaFinishAccess (pSrc, EXA_PREPARE_SRC);
     exaFinishAccess (pDst, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 
     return ret;
 }
@@ -134,14 +142,16 @@ ExaCheckCopyPlane (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 {
     RegionPtr ret;
 
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrc, pDst,
 		  exaDrawableLocation(pSrc), exaDrawableLocation(pDst)));
     exaPrepareAccess (pDst, EXA_PREPARE_DEST);
     exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
-    ret = fbCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty,
+    ret = pGC->ops->CopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty,
 		       bitPlane);
     exaFinishAccess (pSrc, EXA_PREPARE_SRC);
     exaFinishAccess (pDst, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 
     return ret;
 }
@@ -150,85 +160,75 @@ void
 ExaCheckPolyPoint (DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
 		  DDXPointPtr pptInit)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
-    fbPolyPoint (pDrawable, pGC, mode, npt, pptInit);
+    pGC->ops->PolyPoint (pDrawable, pGC, mode, npt, pptInit);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
 ExaCheckPolylines (DrawablePtr pDrawable, GCPtr pGC,
 		  int mode, int npt, DDXPointPtr ppt)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c), width %d, mode %d, count %d\n",
 		  pDrawable, exaDrawableLocation(pDrawable),
 		  pGC->lineWidth, mode, npt));
 
-    if (pGC->lineWidth == 0) {
-	exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
-	exaPrepareAccessGC (pGC);
-	fbPolyLine (pDrawable, pGC, mode, npt, ppt);
-	exaFinishAccessGC (pGC);
-	exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
-	return;
-    }
-    /* fb calls mi functions in the lineWidth != 0 case. */
-    fbPolyLine (pDrawable, pGC, mode, npt, ppt);
+    exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
+    exaPrepareAccessGC (pGC);
+    pGC->ops->Polylines (pDrawable, pGC, mode, npt, ppt);
+    exaFinishAccessGC (pGC);
+    exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
 ExaCheckPolySegment (DrawablePtr pDrawable, GCPtr pGC,
 		    int nsegInit, xSegment *pSegInit)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c) width %d, count %d\n", pDrawable,
 		  exaDrawableLocation(pDrawable), pGC->lineWidth, nsegInit));
-    if (pGC->lineWidth == 0) {
-	exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
-	exaPrepareAccessGC (pGC);
-	fbPolySegment (pDrawable, pGC, nsegInit, pSegInit);
-	exaFinishAccessGC (pGC);
-	exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
-	return;
-    }
-    /* fb calls mi functions in the lineWidth != 0 case. */
-    fbPolySegment (pDrawable, pGC, nsegInit, pSegInit);
+
+    exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
+    exaPrepareAccessGC (pGC);
+    pGC->ops->PolySegment (pDrawable, pGC, nsegInit, pSegInit);
+    exaFinishAccessGC (pGC);
+    exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
 ExaCheckPolyArc (DrawablePtr pDrawable, GCPtr pGC,
 		int narcs, xArc *pArcs)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
 
-    /* Disable this as fbPolyArc can call miZeroPolyArc which in turn
-     * can call accelerated functions, that as yet, haven't been notified
-     * with exaFinishAccess().
-     */
-#if 0
-    if (pGC->lineWidth == 0)
-    {
-	exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
-	exaPrepareAccessGC (pGC);
-	fbPolyArc (pDrawable, pGC, narcs, pArcs);
-	exaFinishAccessGC (pGC);
-	exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
-	return;
-    }
-#endif
-    miPolyArc (pDrawable, pGC, narcs, pArcs);
+    exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
+    exaPrepareAccessGC (pGC);
+    pGC->ops->PolyArc (pDrawable, pGC, narcs, pArcs);
+    exaFinishAccessGC (pGC);
+    exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
 ExaCheckPolyFillRect (DrawablePtr pDrawable, GCPtr pGC,
 		     int nrect, xRectangle *prect)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
 
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
     exaPrepareAccessGC (pGC);
-    fbPolyFillRect (pDrawable, pGC, nrect, prect);
+    pGC->ops->PolyFillRect (pDrawable, pGC, nrect, prect);
     exaFinishAccessGC (pGC);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
@@ -236,13 +236,15 @@ ExaCheckImageGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
 		      int x, int y, unsigned int nglyph,
 		      CharInfoPtr *ppci, pointer pglyphBase)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c)\n", pDrawable,
 		  exaDrawableLocation(pDrawable)));
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
     exaPrepareAccessGC (pGC);
-    fbImageGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+    pGC->ops->ImageGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
     exaFinishAccessGC (pGC);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
@@ -250,13 +252,15 @@ ExaCheckPolyGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
 		     int x, int y, unsigned int nglyph,
 		     CharInfoPtr *ppci, pointer pglyphBase)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("to %p (%c), style %d alu %d\n", pDrawable,
 		  exaDrawableLocation(pDrawable), pGC->fillStyle, pGC->alu));
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
     exaPrepareAccessGC (pGC);
-    fbPolyGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+    pGC->ops->PolyGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
     exaFinishAccessGC (pGC);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
@@ -264,16 +268,18 @@ ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
 		   DrawablePtr pDrawable,
 		   int w, int h, int x, int y)
 {
+    EXA_GC_PROLOGUE(pGC);
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pBitmap, pDrawable,
 		  exaDrawableLocation(&pBitmap->drawable),
 		  exaDrawableLocation(pDrawable)));
     exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
     exaPrepareAccess (&pBitmap->drawable, EXA_PREPARE_SRC);
     exaPrepareAccessGC (pGC);
-    fbPushPixels (pGC, pBitmap, pDrawable, w, h, x, y);
+    pGC->ops->PushPixels (pGC, pBitmap, pDrawable, w, h, x, y);
     exaFinishAccessGC (pGC);
     exaFinishAccess (&pBitmap->drawable, EXA_PREPARE_SRC);
     exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
+    EXA_GC_EPILOGUE(pGC);
 }
 
 void
commit 5e6a06fe691db63ccf2dc7161a1f6c71c09741b7
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Sat Jan 31 16:30:31 2009 +0100

    exa: add GC private

diff --git a/exa/exa.c b/exa/exa.c
index ba063bb..496b898 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -41,6 +41,8 @@ static int exaScreenPrivateKeyIndex;
 DevPrivateKey exaScreenPrivateKey = &exaScreenPrivateKeyIndex;
 static int exaPixmapPrivateKeyIndex;
 DevPrivateKey exaPixmapPrivateKey = &exaPixmapPrivateKeyIndex;
+static int exaGCPrivateKeyIndex;
+DevPrivateKey exaGCPrivateKey = &exaGCPrivateKeyIndex;
 
 #ifdef MITSHM
 static ShmFuncs exaShmFuncs = { NULL, NULL };
@@ -661,6 +663,8 @@ static GCFuncs	exaGCFuncs = {
 static int
 exaCreateGC (GCPtr pGC)
 {
+    ExaGCPriv(pGC);
+
     if (!fbCreateGC (pGC))
 	return FALSE;
 
@@ -890,6 +894,13 @@ exaDriverInit (ScreenPtr		pScreen,
 
     exaDDXDriverInit(pScreen);
 
+    if (!dixRequestPrivate(exaGCPrivateKey, sizeof(ExaGCPrivRec))) {
+	LogMessage(X_WARNING,
+	       "EXA(%d): Failed to allocate GC private\n",
+	       pScreen->myNum);
+	return FALSE;
+    }
+
     /*
      * Replace various fb screen functions
      */
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index cc789c6..3b58948 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -173,9 +173,13 @@ typedef struct {
 
 extern DevPrivateKey exaScreenPrivateKey;
 extern DevPrivateKey exaPixmapPrivateKey;
+extern DevPrivateKey exaGCPrivateKey;
 #define ExaGetScreenPriv(s) ((ExaScreenPrivPtr)dixLookupPrivate(&(s)->devPrivates, exaScreenPrivateKey))
 #define ExaScreenPriv(s)	ExaScreenPrivPtr    pExaScr = ExaGetScreenPriv(s)
 
+#define ExaGetGCPriv(gc) ((ExaGCPrivPtr)dixLookupPrivate(&(gc)->devPrivates, exaGCPrivateKey))
+#define ExaGCPriv(gc) ExaGCPrivPtr pExaGC = ExaGetGCPriv(gc)
+
 /** Align an offset to an arbitrary alignment */
 #define EXA_ALIGN(offset, align) (((offset) + (align) - 1) - \
 	(((offset) + (align) - 1) % (align)))
@@ -236,7 +240,13 @@ typedef struct {
      */
     void *driverPriv;
 } ExaPixmapPrivRec, *ExaPixmapPrivPtr;
- 
+
+typedef struct {
+    /* GC values from the layer below. */
+    GCOps *ops;
+    GCFuncs *funcs;
+} ExaGCPrivRec, *ExaGCPrivPtr;
+
 typedef struct _ExaMigrationRec {
     Bool as_dst;
     Bool as_src;
commit 5cc67ae94c066dcac78072ad8a819c3b602d8bab
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Fri Jan 30 19:32:33 2009 +0100

    exa: kill of exaImageGlyphBlt
    
    - It serves no obvious purpose, yet it directly accesses many fb
    symbols.

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index b70222a..10e7914 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -836,139 +836,6 @@ out:
     REGION_DESTROY(pScreen, pReg);
 }
 
-static void
-exaImageGlyphBlt (DrawablePtr	pDrawable,
-		  GCPtr		pGC,
-		  int		x,
-		  int		y,
-		  unsigned int	nglyph,
-		  CharInfoPtr	*ppciInit,
-		  pointer	pglyphBase)
-{
-    FbGCPrivPtr	    pPriv = fbGetGCPrivate(pGC);
-    CharInfoPtr	    *ppci;
-    CharInfoPtr	    pci;
-    unsigned char   *pglyph;		/* pointer bits in glyph */
-    int		    gWidth, gHeight;	/* width and height of glyph */
-    FbStride	    gStride;		/* stride of glyph */
-    Bool	    opaque;
-    int		    gx, gy;
-    void	    (*glyph) (FbBits *,
-			      FbStride,
-			      int,
-			      FbStip *,
-			      FbBits,
-			      int,
-			      int);
-    FbBits	    *dst;
-    FbStride	    dstStride;
-    int		    dstBpp;
-    int		    dstXoff, dstYoff;
-    FbBits	    depthMask;
-    PixmapPtr	    pPixmap = exaGetDrawablePixmap(pDrawable);
-    ExaPixmapPriv(pPixmap);
-    RegionPtr	    pending_damage = NULL;
-    BoxRec	    extents;
-    int		    xoff, yoff;
-
-    if (pExaPixmap->pDamage)
-	pending_damage = DamagePendingRegion(pExaPixmap->pDamage);
-
-    if (pending_damage) {
-	extents = *REGION_EXTENTS(pScreen, pending_damage);
-
-	if (extents.x1 >= extents.x2 || extents.y1 >= extents.y2)
-	    return;
-
-	depthMask = FbFullMask(pDrawable->depth);
-    }
-
-    if (!pending_damage || (pGC->planemask & depthMask) != depthMask)
-    {
-	ExaCheckImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppciInit, pglyphBase);
-	return;
-    }
-
-    glyph = NULL;
-    switch (pDrawable->bitsPerPixel) {
-    case 8:	glyph = fbGlyph8; break;
-    case 16:    glyph = fbGlyph16; break;
-    case 24:    glyph = fbGlyph24; break;
-    case 32:    glyph = fbGlyph32; break;
-    }
-
-    x += pDrawable->x;
-    y += pDrawable->y;
-
-    exaGetDrawableDeltas(pDrawable, pPixmap, &xoff, &yoff);
-    extents.x1 -= xoff;
-    extents.x2 -= xoff;
-    extents.y1 -= yoff;
-    extents.y2 -= yoff;
-
-    exaPrepareAccessReg (pDrawable, EXA_PREPARE_DEST, pending_damage);
-
-    if (TERMINALFONT (pGC->font) && !glyph)
-    {
-	opaque = TRUE;
-    }
-    else
-    {
-	FbBits fg = fbReplicatePixel (pGC->bgPixel, pDrawable->bitsPerPixel);
-
-	fbSolidBoxClipped (pDrawable,
-			   fbGetCompositeClip(pGC),
-			   extents.x1,
-			   extents.y1,
-			   extents.x2,
-			   extents.y2,
-			   fbAnd (GXcopy, fg, pGC->planemask),
-			   fbXor (GXcopy, fg, pGC->planemask));
-
-	opaque = FALSE;
-    }
-
-    EXA_FALLBACK(("to %p (%c)\n", pDrawable, exaDrawableLocation(pDrawable)));
-
-    exaPrepareAccessGC (pGC);
-
-    fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
-
-    for (ppci = ppciInit; nglyph; nglyph--, x += pci->metrics.characterWidth)
-    {
-	pci = *ppci++;
-	gWidth = GLYPHWIDTHPIXELS(pci);
-	gHeight = GLYPHHEIGHTPIXELS(pci);
-	gx = x + pci->metrics.leftSideBearing;
-	gy = y - pci->metrics.ascent;
-
-	if (!gWidth || !gHeight || (gx + gWidth) <= extents.x1 ||
-	    (gy + gHeight) <= extents.y1 || gx >= extents.x2 ||
-	    gy >= extents.y2)
-	    continue;
-
-	pglyph = FONTGLYPHBITS(pglyphBase, pci);
-
-	if (glyph && gWidth <= sizeof (FbStip) * 8 &&
-	    fbGlyphIn (fbGetCompositeClip(pGC), gx, gy, gWidth, gHeight))
-	{
-	    (*glyph) (dst + (gy + dstYoff) * dstStride, dstStride, dstBpp,
-		      (FbStip *) pglyph, pPriv->fg, gx + dstXoff, gHeight);
-	}
-	else
-	{
-	    RegionPtr pClip = fbGetCompositeClip(pGC);
-
-	    gStride = GLYPHWIDTHBYTESPADDED(pci) / sizeof (FbStip);
-	    fbPutXYImage (pDrawable, pClip, pPriv->fg, pPriv->bg, pPriv->pm,
-			  GXcopy, opaque, gx, gy, gWidth, gHeight,
-			  (FbStip *) pglyph, gStride, 0);
-	}
-    }
-    exaFinishAccessGC (pGC);
-    exaFinishAccess (pDrawable, EXA_PREPARE_DEST);
-}
-
 const GCOps exaOps = {
     exaFillSpans,
     ExaCheckSetSpans,
@@ -987,7 +854,7 @@ const GCOps exaOps = {
     miPolyText16,
     miImageText8,
     miImageText16,
-    exaImageGlyphBlt,
+    ExaCheckImageGlyphBlt,
     ExaCheckPolyGlyphBlt,
     ExaCheckPushPixels,
 };
commit 6483834200fab90164c27c72d4710014edeb4479
Author: Maarten Maathuis <madman2003 at gmail.com>
Date:   Fri Jan 30 18:40:46 2009 +0100

    exa: Remove one of the many calls directly into the fb layer.

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index f72a08a..b70222a 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -149,6 +149,7 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     int xoff, yoff;
     int bpp = pDrawable->bitsPerPixel;
     Bool access_prepared = FALSE;
+    Bool ret = TRUE;
 
     if (pExaPixmap->accel_blocked)
 	return FALSE;
@@ -210,33 +211,12 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
 	src = bits + (y1 - y) * src_stride + (x1 - x) * (bpp / 8);
 	ok = pExaScr->info->UploadToScreen(pPix, x1 + xoff, y1 + yoff,
 					   x2 - x1, y2 - y1, src, src_stride);
-	/* If we fail to accelerate the upload, fall back to using unaccelerated
-	 * fb calls.
+	/* We have to fall back completely, and ignore what has already been completed.
+	 * Messing with the fb layer directly like we used to is completely unacceptable.
 	 */
 	if (!ok) {
-	    FbStip *dst;
-	    FbStride dst_stride;
-	    int	dstBpp;
-	    int	dstXoff, dstYoff;
-
-	    if (!access_prepared) {
-		ExaDoPrepareAccess(pDrawable, EXA_PREPARE_DEST);
-
-		access_prepared = TRUE;
-	    }
-
-	    fbGetStipDrawable(pDrawable, dst, dst_stride, dstBpp,
-			      dstXoff, dstYoff);
-
-	    fbBltStip((FbStip *)bits + (y1 - y) * (src_stride / sizeof(FbStip)),
-		      src_stride / sizeof(FbStip),
-		      (x1 - x) * dstBpp,
-		      dst + (y1 + dstYoff) * dst_stride,
-		      dst_stride,
-		      (x1 + dstXoff) * dstBpp,
-		      (x2 - x1) * dstBpp,
-		      y2 - y1,
-		      GXcopy, FB_ALLONES, dstBpp);
+	    ret = FALSE;
+	    break;
 	}
     }
 
@@ -245,7 +225,7 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     else
 	exaMarkSync(pDrawable->pScreen);
 
-    return TRUE;
+    return ret;
 }
 
 static void


More information about the xorg-commit mailing list