[PATCH 9/9] exa: fix exaCopyArea and friends.

2009-02-04 Thread Maarten Maathuis
---
 exa/Makefile.am |3 ++-
 exa/exa_accel.c |   44 ++--
 exa/exa_priv.h  |6 +-
 exa/exa_render.c|   14 --
 exa/exa_unaccel.c   |   15 +++
 fb/fbcopy_helpers.c |6 +++---
 fb/fbcopy_helpers.h |   12 ++--
 7 files changed, 77 insertions(+), 23 deletions(-)

diff --git a/exa/Makefile.am b/exa/Makefile.am
index 2b3f1e4..409dd09 100644
--- a/exa/Makefile.am
+++ b/exa/Makefile.am
@@ -12,11 +12,12 @@ INCLUDES = \
$(XORG_INCS) \
-I$(srcdir)/../miext/cw
 
-AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS)
+AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS) -DFB_WRAP_PREFIX=exa
 
 libexa_la_SOURCES = \
exa.c \
exa.h \
+   ../fb/fbcopy_helpers.c \
exa_accel.c \
exa_glyphs.c \
exa_migration.c \
diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 02858f1..db79cee 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -359,7 +359,7 @@ exaCopyNtoNTwoDir (DrawablePtr pSrcDrawable, DrawablePtr 
pDstDrawable,
 return TRUE;
 }
 
-void
+Bool
 exaCopyNtoN (DrawablePtrpSrcDrawable,
 DrawablePtrpDstDrawable,
 GCPtr  pGC,
@@ -383,7 +383,7 @@ exaCopyNtoN (DrawablePtrpSrcDrawable,
 
 /* avoid doing copy operations if no boxes */
 if (nbox == 0)
-   return;
+   return TRUE;
 
 pSrcPixmap = exaGetDrawablePixmap (pSrcDrawable);
 pDstPixmap = exaGetDrawablePixmap (pDstDrawable);
@@ -492,15 +492,15 @@ exaCopyNtoN (DrawablePtrpSrcDrawable,
 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);
+if (dstregion) {
+   REGION_UNINIT(pScreen, dstregion);
+   REGION_DESTROY(pScreen, dstregion);
+}
+if (srcregion) {
+   REGION_UNINIT(pScreen, srcregion);
+   REGION_DESTROY(pScreen, srcregion);
+}
+return FALSE;
 
 out:
 if (dstregion) {
@@ -511,6 +511,8 @@ out:
REGION_UNINIT(pScreen, srcregion);
REGION_DESTROY(pScreen, srcregion);
 }
+
+return TRUE;
 }
 
 RegionPtr
@@ -518,15 +520,25 @@ exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr 
pDstDrawable, GCPtr pGC,
int srcx, int srcy, int width, int height, int dstx, int dsty)
 {
 ExaScreenPriv (pDstDrawable-pScreen);
+RegionPtr ret;
+Bool success;
 
 if (pExaScr-swappedOut) {
 return  ExaCheckCopyArea(pSrcDrawable, pDstDrawable, pGC,
  srcx, srcy, width, height, dstx, dsty);
 }
 
-return  fbDoCopy (pSrcDrawable, pDstDrawable, pGC,
+ret = exaDoCopy (pSrcDrawable, pDstDrawable, pGC,
   srcx, srcy, width, height,
-  dstx, dsty, exaCopyNtoN, 0, NULL);
+  dstx, dsty, exaCopyNtoN, 0, NULL, success);
+
+if (!success) {
+   xfree(ret);
+   return ExaCheckCopyArea(pSrcDrawable, pDstDrawable, pGC,
+ srcx, srcy, width, height, dstx, dsty);
+}
+
+return ret;
 }
 
 static void
@@ -865,6 +877,7 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, 
RegionPtr prgnSrc)
 RegionRec  rgnDst;
 intdx, dy;
 PixmapPtr  pPixmap = (*pWin-drawable.pScreen-GetWindowPixmap) (pWin);
+Bool ret;
 
 dx = ptOldOrg.x - pWin-drawable.x;
 dy = ptOldOrg.y - pWin-drawable.y;
@@ -879,11 +892,14 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, 
RegionPtr prgnSrc)
  -pPixmap-screen_x, -pPixmap-screen_y);
 #endif
 
-fbCopyRegion (pPixmap-drawable, pPixmap-drawable,
+ret = exaCopyRegion (pPixmap-drawable, pPixmap-drawable,
  NULL,
  rgnDst, dx, dy, exaCopyNtoN, 0, NULL);
 
 REGION_UNINIT(pWin-drawable.pScreen, rgnDst);
+
+if (!ret)
+   ExaCheckCopyWindow(pWin, ptOldOrg, prgnSrc);
 }
 
 static Bool
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 6d7c1dd..c555f85 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -55,6 +55,7 @@
 #include glyphstr.h
 #endif
 #include damage.h
+#include fbcopy_helpers.h
 
 #define DEBUG_TRACE_FALL   0
 #define DEBUG_MIGRATE  0
@@ -379,6 +380,9 @@ ExaCheckAddTraps (PicturePtrpPicture,
  int   ntrap,
  xTrap *traps);
 
+void
+ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
+
 /* exa_accel.c */
 
 static _X_INLINE Bool
@@ -465,7 +469,7 @@ RegionPtr
 exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr 

[PATCH 9/9] exa: fix exaCopyArea and friends.

2009-02-03 Thread Maarten Maathuis
---
 exa/Makefile.am |3 ++-
 exa/exa_accel.c |   44 ++--
 exa/exa_priv.h  |6 +-
 exa/exa_render.c|   14 --
 exa/exa_unaccel.c   |   15 +++
 fb/fbcopy_helpers.h |5 +
 6 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/exa/Makefile.am b/exa/Makefile.am
index 2b3f1e4..f344a05 100644
--- a/exa/Makefile.am
+++ b/exa/Makefile.am
@@ -12,11 +12,12 @@ INCLUDES = \
$(XORG_INCS) \
-I$(srcdir)/../miext/cw
 
-AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS)
+AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS) -DEXA_WRAPPER
 
 libexa_la_SOURCES = \
exa.c \
exa.h \
+   ../fb/fbcopy_helpers.c \
exa_accel.c \
exa_glyphs.c \
exa_migration.c \
diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 02858f1..db79cee 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -359,7 +359,7 @@ exaCopyNtoNTwoDir (DrawablePtr pSrcDrawable, DrawablePtr 
pDstDrawable,
 return TRUE;
 }
 
-void
+Bool
 exaCopyNtoN (DrawablePtrpSrcDrawable,
 DrawablePtrpDstDrawable,
 GCPtr  pGC,
@@ -383,7 +383,7 @@ exaCopyNtoN (DrawablePtrpSrcDrawable,
 
 /* avoid doing copy operations if no boxes */
 if (nbox == 0)
-   return;
+   return TRUE;
 
 pSrcPixmap = exaGetDrawablePixmap (pSrcDrawable);
 pDstPixmap = exaGetDrawablePixmap (pDstDrawable);
@@ -492,15 +492,15 @@ exaCopyNtoN (DrawablePtrpSrcDrawable,
 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);
+if (dstregion) {
+   REGION_UNINIT(pScreen, dstregion);
+   REGION_DESTROY(pScreen, dstregion);
+}
+if (srcregion) {
+   REGION_UNINIT(pScreen, srcregion);
+   REGION_DESTROY(pScreen, srcregion);
+}
+return FALSE;
 
 out:
 if (dstregion) {
@@ -511,6 +511,8 @@ out:
REGION_UNINIT(pScreen, srcregion);
REGION_DESTROY(pScreen, srcregion);
 }
+
+return TRUE;
 }
 
 RegionPtr
@@ -518,15 +520,25 @@ exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr 
pDstDrawable, GCPtr pGC,
int srcx, int srcy, int width, int height, int dstx, int dsty)
 {
 ExaScreenPriv (pDstDrawable-pScreen);
+RegionPtr ret;
+Bool success;
 
 if (pExaScr-swappedOut) {
 return  ExaCheckCopyArea(pSrcDrawable, pDstDrawable, pGC,
  srcx, srcy, width, height, dstx, dsty);
 }
 
-return  fbDoCopy (pSrcDrawable, pDstDrawable, pGC,
+ret = exaDoCopy (pSrcDrawable, pDstDrawable, pGC,
   srcx, srcy, width, height,
-  dstx, dsty, exaCopyNtoN, 0, NULL);
+  dstx, dsty, exaCopyNtoN, 0, NULL, success);
+
+if (!success) {
+   xfree(ret);
+   return ExaCheckCopyArea(pSrcDrawable, pDstDrawable, pGC,
+ srcx, srcy, width, height, dstx, dsty);
+}
+
+return ret;
 }
 
 static void
@@ -865,6 +877,7 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, 
RegionPtr prgnSrc)
 RegionRec  rgnDst;
 intdx, dy;
 PixmapPtr  pPixmap = (*pWin-drawable.pScreen-GetWindowPixmap) (pWin);
+Bool ret;
 
 dx = ptOldOrg.x - pWin-drawable.x;
 dy = ptOldOrg.y - pWin-drawable.y;
@@ -879,11 +892,14 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, 
RegionPtr prgnSrc)
  -pPixmap-screen_x, -pPixmap-screen_y);
 #endif
 
-fbCopyRegion (pPixmap-drawable, pPixmap-drawable,
+ret = exaCopyRegion (pPixmap-drawable, pPixmap-drawable,
  NULL,
  rgnDst, dx, dy, exaCopyNtoN, 0, NULL);
 
 REGION_UNINIT(pWin-drawable.pScreen, rgnDst);
+
+if (!ret)
+   ExaCheckCopyWindow(pWin, ptOldOrg, prgnSrc);
 }
 
 static Bool
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 6d7c1dd..c555f85 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -55,6 +55,7 @@
 #include glyphstr.h
 #endif
 #include damage.h
+#include fbcopy_helpers.h
 
 #define DEBUG_TRACE_FALL   0
 #define DEBUG_MIGRATE  0
@@ -379,6 +380,9 @@ ExaCheckAddTraps (PicturePtrpPicture,
  int   ntrap,
  xTrap *traps);
 
+void
+ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
+
 /* exa_accel.c */
 
 static _X_INLINE Bool
@@ -465,7 +469,7 @@ RegionPtr
 exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
int srcx, int srcy, 

[PATCH 9/9] exa: fix exaCopyArea and friends.

2009-02-03 Thread Maarten Maathuis
---
 exa/Makefile.am |3 ++-
 exa/exa_accel.c |   44 ++--
 exa/exa_priv.h  |6 +-
 exa/exa_render.c|   14 --
 exa/exa_unaccel.c   |   15 +++
 fb/fbcopy_helpers.h |5 +
 6 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/exa/Makefile.am b/exa/Makefile.am
index 2b3f1e4..f344a05 100644
--- a/exa/Makefile.am
+++ b/exa/Makefile.am
@@ -12,11 +12,12 @@ INCLUDES = \
$(XORG_INCS) \
-I$(srcdir)/../miext/cw
 
-AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS)
+AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS) -DEXA_WRAPPER
 
 libexa_la_SOURCES = \
exa.c \
exa.h \
+   ../fb/fbcopy_helpers.c \
exa_accel.c \
exa_glyphs.c \
exa_migration.c \
diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 02858f1..db79cee 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -359,7 +359,7 @@ exaCopyNtoNTwoDir (DrawablePtr pSrcDrawable, DrawablePtr 
pDstDrawable,
 return TRUE;
 }
 
-void
+Bool
 exaCopyNtoN (DrawablePtrpSrcDrawable,
 DrawablePtrpDstDrawable,
 GCPtr  pGC,
@@ -383,7 +383,7 @@ exaCopyNtoN (DrawablePtrpSrcDrawable,
 
 /* avoid doing copy operations if no boxes */
 if (nbox == 0)
-   return;
+   return TRUE;
 
 pSrcPixmap = exaGetDrawablePixmap (pSrcDrawable);
 pDstPixmap = exaGetDrawablePixmap (pDstDrawable);
@@ -492,15 +492,15 @@ exaCopyNtoN (DrawablePtrpSrcDrawable,
 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);
+if (dstregion) {
+   REGION_UNINIT(pScreen, dstregion);
+   REGION_DESTROY(pScreen, dstregion);
+}
+if (srcregion) {
+   REGION_UNINIT(pScreen, srcregion);
+   REGION_DESTROY(pScreen, srcregion);
+}
+return FALSE;
 
 out:
 if (dstregion) {
@@ -511,6 +511,8 @@ out:
REGION_UNINIT(pScreen, srcregion);
REGION_DESTROY(pScreen, srcregion);
 }
+
+return TRUE;
 }
 
 RegionPtr
@@ -518,15 +520,25 @@ exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr 
pDstDrawable, GCPtr pGC,
int srcx, int srcy, int width, int height, int dstx, int dsty)
 {
 ExaScreenPriv (pDstDrawable-pScreen);
+RegionPtr ret;
+Bool success;
 
 if (pExaScr-swappedOut) {
 return  ExaCheckCopyArea(pSrcDrawable, pDstDrawable, pGC,
  srcx, srcy, width, height, dstx, dsty);
 }
 
-return  fbDoCopy (pSrcDrawable, pDstDrawable, pGC,
+ret = exaDoCopy (pSrcDrawable, pDstDrawable, pGC,
   srcx, srcy, width, height,
-  dstx, dsty, exaCopyNtoN, 0, NULL);
+  dstx, dsty, exaCopyNtoN, 0, NULL, success);
+
+if (!success) {
+   xfree(ret);
+   return ExaCheckCopyArea(pSrcDrawable, pDstDrawable, pGC,
+ srcx, srcy, width, height, dstx, dsty);
+}
+
+return ret;
 }
 
 static void
@@ -865,6 +877,7 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, 
RegionPtr prgnSrc)
 RegionRec  rgnDst;
 intdx, dy;
 PixmapPtr  pPixmap = (*pWin-drawable.pScreen-GetWindowPixmap) (pWin);
+Bool ret;
 
 dx = ptOldOrg.x - pWin-drawable.x;
 dy = ptOldOrg.y - pWin-drawable.y;
@@ -879,11 +892,14 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, 
RegionPtr prgnSrc)
  -pPixmap-screen_x, -pPixmap-screen_y);
 #endif
 
-fbCopyRegion (pPixmap-drawable, pPixmap-drawable,
+ret = exaCopyRegion (pPixmap-drawable, pPixmap-drawable,
  NULL,
  rgnDst, dx, dy, exaCopyNtoN, 0, NULL);
 
 REGION_UNINIT(pWin-drawable.pScreen, rgnDst);
+
+if (!ret)
+   ExaCheckCopyWindow(pWin, ptOldOrg, prgnSrc);
 }
 
 static Bool
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 6d7c1dd..c555f85 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -55,6 +55,7 @@
 #include glyphstr.h
 #endif
 #include damage.h
+#include fbcopy_helpers.h
 
 #define DEBUG_TRACE_FALL   0
 #define DEBUG_MIGRATE  0
@@ -379,6 +380,9 @@ ExaCheckAddTraps (PicturePtrpPicture,
  int   ntrap,
  xTrap *traps);
 
+void
+ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
+
 /* exa_accel.c */
 
 static _X_INLINE Bool
@@ -465,7 +469,7 @@ RegionPtr
 exaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
int srcx, int srcy,