here's a patch which mainly does 3 things:
- convert sis, mach64, and radeon to spantmp2.
The sis and mach64 drivers got a slight change, previously you could not read back alpha values (always 0xff) and I don't think there was a good reason for that?
The 3 intel drivers and the s3v are not converted due to their support of a RGB555 format spantmp2 can't handle (actually, the i810 does not support the 555 format in its span functions, the driver elsewhere has support for it, this probably can't be right). tdfx and ffb are not converted since they support a 888 format. gamma is not converted since it performs some unusual always-round-up tricks when using RGB565 format. trident is not converted since it doesn't support span functions yet at all :-).


- remove HW_CLIPLOOP, HW_ENDCLIPLOOP, CLIPPIXEL and CLIPSPAN macros out of the drivers whenever possible, since they are almost always identical. ffb uses very different macros, and some drivers do not use the driDrawable struct for HW_CLIPLOOP (which btw is interesting, I'm not quite sure why some drivers need to handle that differently, I didn't look too much into it but the difference is due to the handling of front and back buffers somehow), so they keep their own definitions hopefully.
There are probably more macro definitions which could be factored out.


- change CLIPSPAN to never return negative number of pixels (only change that once! not a dozen times, which is why I've done that macro definition removal in the first place...).

Does this look sane? Driver source code should get quite a bit smaller overall.

Roland

Index: common/depthtmp.h
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/common/depthtmp.h,v
retrieving revision 1.7
diff -u -r1.7 depthtmp.h
--- common/depthtmp.h   14 Feb 2005 09:27:38 -0000      1.7
+++ common/depthtmp.h   3 Mar 2005 03:24:43 -0000
@@ -1,24 +1,19 @@
 /* $XFree86: xc/lib/GL/mesa/src/drv/common/depthtmp.h,v 1.5 2001/03/21 
16:14:20 dawes Exp $ */
 
+#include "spantmp_common.h"
+
 #ifndef DBG
 #define DBG 0
 #endif
 
-
 #ifndef HAVE_HW_DEPTH_SPANS
 #define HAVE_HW_DEPTH_SPANS 0
 #endif
+
 #ifndef HAVE_HW_DEPTH_PIXELS
 #define HAVE_HW_DEPTH_PIXELS 0
 #endif
 
-#ifndef HW_READ_LOCK
-#define HW_READ_LOCK()         HW_LOCK()
-#endif
-#ifndef HW_READ_UNLOCK
-#define HW_READ_UNLOCK()       HW_UNLOCK()
-#endif
-
 static void TAG(WriteDepthSpan)( GLcontext *ctx,
                              GLuint n, GLint x, GLint y,
                                 const GLdepth *depth,
Index: common/spantmp.h
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/common/spantmp.h,v
retrieving revision 1.5
diff -u -r1.5 spantmp.h
--- common/spantmp.h    14 Feb 2005 09:27:38 -0000      1.5
+++ common/spantmp.h    3 Mar 2005 03:24:43 -0000
@@ -27,26 +27,12 @@
  *    Gareth Hughes <[EMAIL PROTECTED]>
  */
 
+#include "spantmp_common.h"
+
 #ifndef DBG
 #define DBG 0
 #endif
 
-#ifndef HW_WRITE_LOCK
-#define HW_WRITE_LOCK()                HW_LOCK()
-#endif
-
-#ifndef HW_WRITE_UNLOCK
-#define HW_WRITE_UNLOCK()      HW_UNLOCK()
-#endif
-
-#ifndef HW_READ_LOCK
-#define HW_READ_LOCK()         HW_LOCK()
-#endif
-
-#ifndef HW_READ_UNLOCK
-#define HW_READ_UNLOCK()       HW_UNLOCK()
-#endif
-
 #ifndef HW_READ_CLIPLOOP
 #define HW_READ_CLIPLOOP()     HW_CLIPLOOP()
 #endif
Index: common/spantmp2.h
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/common/spantmp2.h,v
retrieving revision 1.6
diff -u -r1.6 spantmp2.h
--- common/spantmp2.h   15 Jan 2005 14:35:35 -0000      1.6
+++ common/spantmp2.h   3 Mar 2005 03:24:43 -0000
@@ -34,27 +34,12 @@
  */
 
 #include "colormac.h"
+#include "spantmp_common.h"
 
 #ifndef DBG
 #define DBG 0
 #endif
 
-#ifndef HW_WRITE_LOCK
-#define HW_WRITE_LOCK()                HW_LOCK()
-#endif
-
-#ifndef HW_WRITE_UNLOCK
-#define HW_WRITE_UNLOCK()      HW_UNLOCK()
-#endif
-
-#ifndef HW_READ_LOCK
-#define HW_READ_LOCK()         HW_LOCK()
-#endif
-
-#ifndef HW_READ_UNLOCK
-#define HW_READ_UNLOCK()       HW_UNLOCK()
-#endif
-
 #ifndef HW_READ_CLIPLOOP
 #define HW_READ_CLIPLOOP()     HW_CLIPLOOP()
 #endif
Index: common/stenciltmp.h
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/common/stenciltmp.h,v
retrieving revision 1.4
diff -u -r1.4 stenciltmp.h
--- common/stenciltmp.h 14 Feb 2005 09:27:38 -0000      1.4
+++ common/stenciltmp.h 3 Mar 2005 03:24:44 -0000
@@ -1,23 +1,11 @@
 /* $XFree86: xc/lib/GL/mesa/src/drv/common/stenciltmp.h,v 1.3 2001/03/21 
16:14:20 dawes Exp $ */
 
+#include "spantmp_common.h"
+
 #ifndef DBG
 #define DBG 0
 #endif
 
-#ifndef HW_WRITE_LOCK
-#define HW_WRITE_LOCK()                HW_LOCK()
-#endif
-#ifndef HW_WRITE_UNLOCK
-#define HW_WRITE_UNLOCK()      HW_UNLOCK()
-#endif
-
-#ifndef HW_READ_LOCK
-#define HW_READ_LOCK()         HW_LOCK()
-#endif
-#ifndef HW_READ_UNLOCK
-#define HW_READ_UNLOCK()       HW_UNLOCK()
-#endif
-
 static void TAG(WriteStencilSpan)( GLcontext *ctx,
                                   GLuint n, GLint x, GLint y,
                                   const GLstencil *stencil, 
Index: gamma/gamma_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/gamma/gamma_span.c,v
retrieving revision 1.6
diff -u -r1.6 gamma_span.c
--- gamma/gamma_span.c  20 Jan 2005 13:24:08 -0000      1.6
+++ gamma/gamma_span.c  3 Mar 2005 03:24:46 -0000
@@ -40,21 +40,6 @@
 
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
-
-#define CLIPPIXEL( _x, _y )                                            \
-   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP( _y )           (height - _y - 1)
 
 #define HW_LOCK()                                                      \
@@ -63,21 +48,6 @@
    gammaGetLock( gmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT );         \
    GAMMAHW_LOCK( gmesa );
 
-#define HW_CLIPLOOP()                                                  \
-   do {                                                                        
\
-      __DRIdrawablePrivate *dPriv = gmesa->driDrawable;                        
\
-      int _nc = dPriv->numClipRects;                                   \
-                                                                       \
-      while ( _nc-- ) {                                                        
\
-        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
-        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
-        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
-        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-#define HW_ENDCLIPLOOP()                                               \
-      }                                                                        
\
-   } while (0)
-
 #define HW_UNLOCK() GAMMAHW_UNLOCK( gmesa )
 
 
Index: i810/i810span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i810/i810span.c,v
retrieving revision 1.4
diff -u -r1.4 i810span.c
--- i810/i810span.c     20 Jan 2005 13:24:08 -0000      1.4
+++ i810/i810span.c     3 Mar 2005 03:24:46 -0000
@@ -41,39 +41,10 @@
 #define INIT_MONO_PIXEL(p, color) \
    p = PACK_COLOR_565( color[0], color[1], color[2] )
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
-                         _y >= miny && _y < maxy)
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP(_y) (height - _y - 1)
 
 #define HW_LOCK()
 
-#define HW_CLIPLOOP()                                          \
-  do {                                                         \
-    __DRIdrawablePrivate *dPriv = imesa->driDrawable;          \
-    int _nc = dPriv->numClipRects;                             \
-    while (_nc--) {                                            \
-       int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;                \
-       int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;        \
-       int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;                \
-       int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-
-#define HW_ENDCLIPLOOP()                       \
-    }                                          \
-  } while (0)
-
 #define HW_UNLOCK()
 
 /* 16 bit, 565 rgb color spanline and pixel functions
Index: i830/i830_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i830/i830_span.c,v
retrieving revision 1.3
diff -u -r1.3 i830_span.c
--- i830/i830_span.c    7 May 2004 22:46:37 -0000       1.3
+++ i830/i830_span.c    3 Mar 2005 03:24:46 -0000
@@ -81,39 +81,11 @@
 #define INIT_MONO_PIXEL(p,color)\
         p = PACK_COLOR_565(color[0],color[1],color[2])
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
-                         _y >= miny && _y < maxy)
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                \
-   } else {                                                            \
-      _n1 = _n;                                                        \
-      _x1 = _x;                                                        \
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                \
-   }
 
 #define Y_FLIP(_y) (height - _y - 1)
 
-
 #define HW_LOCK()
 
-#define HW_CLIPLOOP()                                          \
-  do {                                                         \
-    __DRIdrawablePrivate *dPriv = imesa->driDrawable;          \
-    int _nc = dPriv->numClipRects;                             \
-    while (_nc--) {                                            \
-       int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;                \
-       int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;        \
-       int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;                \
-       int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-
-#define HW_ENDCLIPLOOP()                       \
-    }                                          \
-  } while (0)
-
 #define HW_UNLOCK()
 
 /* 16 bit, 565 rgb color spanline and pixel functions
Index: i915/intel_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_span.c,v
retrieving revision 1.4
diff -u -r1.4 intel_span.c
--- i915/intel_span.c   20 Jan 2005 13:24:08 -0000      1.4
+++ i915/intel_span.c   3 Mar 2005 03:24:46 -0000
@@ -69,39 +69,10 @@
 #define INIT_MONO_PIXEL(p,color)\
         p = INTEL_PACKCOLOR565(color[0],color[1],color[2])
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
-                         _y >= miny && _y < maxy)
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                \
-   } else {                                                            \
-      _n1 = _n;                                                        \
-      _x1 = _x;                                                        \
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                \
-   }
-
 #define Y_FLIP(_y) (height - _y - 1)
 
-
 #define HW_LOCK()
 
-#define HW_CLIPLOOP()                                          \
-  do {                                                         \
-    __DRIdrawablePrivate *dPriv = intel->driDrawable;          \
-    int _nc = dPriv->numClipRects;                             \
-    while (_nc--) {                                            \
-       int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;                \
-       int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;        \
-       int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;                \
-       int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-
-#define HW_ENDCLIPLOOP()                       \
-    }                                          \
-  } while (0)
-
 #define HW_UNLOCK()
 
 /* 16 bit, 565 rgb color spanline and pixel functions
Index: mach64/mach64_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/mach64/mach64_span.c,v
retrieving revision 1.2
diff -u -r1.2 mach64_span.c
--- mach64/mach64_span.c        21 Mar 2004 17:05:03 -0000      1.2
+++ mach64/mach64_span.c        3 Mar 2005 03:24:46 -0000
@@ -26,7 +26,7 @@
  * Authors:
  *     Gareth Hughes <[EMAIL PROTECTED]>
  *     Leif Delgass <[EMAIL PROTECTED]>
- *     Jos�Fonseca <[EMAIL PROTECTED]>
+ *     Jos�Fonseca <[EMAIL PROTECTED]>
  */
 
 #include "mach64_context.h"
@@ -70,19 +70,6 @@
 
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
-#define CLIPPIXEL( _x, _y )                                            \
-   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if (( _y < miny) || (_y >= maxy)) {                                 \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if (_x1 < minx) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx;  \
-      if (_x1 + _n1 >= maxx) n1 -= (_x1 + n1 - maxx);                  \
-   }
 
 #define Y_FLIP( _y )   (height - _y - 1)
 
@@ -117,58 +104,28 @@
 
 /* 16 bit, RGB565 color spanline and pixel functions
  */
-#undef INIT_MONO_PIXEL
-#define INIT_MONO_PIXEL(p, color) \
-  p = MACH64PACKCOLOR565( color[0], color[1], color[2] )
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
-   *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)r & 0xf8) << 8) |    \
-                                          (((int)g & 0xfc) << 3) |     \
-                                          (((int)b & 0xf8) >> 3))
-
-#define WRITE_PIXEL( _x, _y, p )                                       \
-    *(GLushort *)(buf + _x*2 + _y*pitch) = p
-
-#define READ_RGBA( rgba, _x, _y )                                      \
-    do {                                                               \
-       GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch);         \
-       rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8;                       \
-       rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc;                       \
-       rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;                       \
-       rgba[3] = 0xff;                                                 \
-    } while (0)
-
-#define TAG(x) mach64##x##_RGB565
-#include "spantmp.h"
-
+#define GET_SRC_PTR(_x, _y) (read_buf + _x * 2 + _y * pitch)
+#define GET_DST_PTR(_x, _y) (     buf + _x * 2 + _y * pitch)
+#define SPANTMP_PIXEL_FMT GL_RGB
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
+
+#define TAG(x)    mach64##x##_RGB565
+#define TAG2(x,y) mach64##x##_RGB565##y
+#include "spantmp2.h"
 
 
 /* 32 bit, ARGB8888 color spanline and pixel functions
  */
-#undef INIT_MONO_PIXEL
-#define INIT_MONO_PIXEL(p, color) \
-  p = MACH64PACKCOLOR8888( color[0], color[1], color[2], color[3] )
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
-   *(GLuint *)(buf + _x*4 + _y*pitch) = ((b <<  0) |                   \
-                                        (g <<  8) |                    \
-                                        (r << 16) |                    \
-                                        (a << 24) )
-
-#define WRITE_PIXEL( _x, _y, p )                                       \
-   *(GLuint *)(buf + _x*4 + _y*pitch) = p
-
-#define READ_RGBA( rgba, _x, _y )                                      \
-do {                                                                   \
-   GLuint p = *(GLuint *)(read_buf + _x*4 + _y*pitch);                 \
-   rgba[0] = (p >> 16) & 0xff;                                         \
-   rgba[1] = (p >>  8) & 0xff;                                         \
-   rgba[2] = (p >>  0) & 0xff;                                         \
-   rgba[3] = 0xff; /*(p >> 24) & 0xff;*/                               \
-} while (0)
-
-#define TAG(x) mach64##x##_ARGB8888
-#include "spantmp.h"
+/* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
+   Was there a reason to do so ? If so that'll won't work with that 
template... */
+#define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * pitch)
+#define GET_DST_PTR(_x, _y) (     buf + _x * 4 + _y * pitch)
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
+
+#define TAG(x)    mach64##x##_ARGB8888
+#define TAG2(x,y) mach64##x##_ARGB8888##y
+#include "spantmp2.h"
 
 
 
@@ -228,24 +185,11 @@
 
    switch ( mmesa->mach64Screen->cpp ) {
    case 2:
-      swdd->WriteRGBASpan      = mach64WriteRGBASpan_RGB565;
-      swdd->WriteRGBSpan       = mach64WriteRGBSpan_RGB565;
-      swdd->WriteMonoRGBASpan  = mach64WriteMonoRGBASpan_RGB565;
-      swdd->WriteRGBAPixels    = mach64WriteRGBAPixels_RGB565;
-      swdd->WriteMonoRGBAPixels        = mach64WriteMonoRGBAPixels_RGB565;
-      swdd->ReadRGBASpan       = mach64ReadRGBASpan_RGB565;
-      swdd->ReadRGBAPixels     = mach64ReadRGBAPixels_RGB565;
+      mach64InitPointers_RGB565( swdd );
       break;
 
    case 4:
-      swdd->WriteRGBASpan      = mach64WriteRGBASpan_ARGB8888;
-      swdd->WriteRGBSpan       = mach64WriteRGBSpan_ARGB8888;
-      swdd->WriteMonoRGBASpan  = mach64WriteMonoRGBASpan_ARGB8888;
-      swdd->WriteRGBAPixels    = mach64WriteRGBAPixels_ARGB8888;
-      swdd->WriteMonoRGBAPixels        = mach64WriteMonoRGBAPixels_ARGB8888;
-      swdd->ReadRGBASpan       = mach64ReadRGBASpan_ARGB8888;
-      swdd->ReadRGBAPixels     = mach64ReadRGBAPixels_ARGB8888;
-
+      mach64InitPointers_ARGB8888( swdd );
       break;
 
    default:
Index: mga/mgaspan.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/mga/mgaspan.c,v
retrieving revision 1.8
diff -u -r1.8 mgaspan.c
--- mga/mgaspan.c       20 Jan 2005 13:24:08 -0000      1.8
+++ mga/mgaspan.c       3 Mar 2005 03:24:46 -0000
@@ -67,19 +67,6 @@
 
 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS 
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
-                         _y >= miny && _y < maxy)
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 
 #define HW_LOCK()                              \
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);     \
Index: r128/r128_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r128/r128_span.c,v
retrieving revision 1.4
diff -u -r1.4 r128_span.c
--- r128/r128_span.c    20 Jan 2005 13:24:08 -0000      1.4
+++ r128/r128_span.c    3 Mar 2005 03:24:46 -0000
@@ -75,21 +75,6 @@
 
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
-
-#define CLIPPIXEL( _x, _y )                                            \
-   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP( _y )           (height - _y - 1)
 
 
@@ -99,21 +84,6 @@
    LOCK_HARDWARE( rmesa );                                             \
    r128WaitForIdleLocked( rmesa );
 
-#define HW_CLIPLOOP()                                                  \
-   do {                                                                        
\
-      __DRIdrawablePrivate *dPriv = rmesa->driDrawable;                        
\
-      int _nc = dPriv->numClipRects;                                   \
-                                                                       \
-      while ( _nc-- ) {                                                        
\
-        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
-        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
-        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
-        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-#define HW_ENDCLIPLOOP()                                               \
-      }                                                                        
\
-   } while (0)
-
 #define HW_UNLOCK()                                                    \
    UNLOCK_HARDWARE( rmesa )
 
Index: r200/r200_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r200/r200_span.c,v
retrieving revision 1.7
diff -u -r1.7 r200_span.c
--- r200/r200_span.c    26 Jan 2005 18:05:03 -0000      1.7
+++ r200/r200_span.c    3 Mar 2005 03:24:47 -0000
@@ -77,41 +77,10 @@
 
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
-
-#define CLIPPIXEL( _x, _y )                                            \
-   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP( _y )           (height - _y - 1)
 
-
 #define HW_LOCK() 
 
-#define HW_CLIPLOOP()                                                  \
-   do {                                                                        
\
-      __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;               \
-      int _nc = dPriv->numClipRects;                                   \
-                                                                       \
-      while ( _nc-- ) {                                                        
\
-        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
-        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
-        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
-        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-#define HW_ENDCLIPLOOP()                                               \
-      }                                                                        
\
-   } while (0)
-
 #define HW_UNLOCK()                                                    
 
 
Index: radeon/radeon_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/radeon/radeon_span.c,v
retrieving revision 1.4
diff -u -r1.4 radeon_span.c
--- radeon/radeon_span.c        26 Jan 2005 18:05:03 -0000      1.4
+++ radeon/radeon_span.c        3 Mar 2005 03:24:49 -0000
@@ -78,41 +78,10 @@
 
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
-
-#define CLIPPIXEL( _x, _y )                                            \
-   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP( _y )           (height - _y - 1)
 
-
 #define HW_LOCK() 
 
-#define HW_CLIPLOOP()                                                  \
-   do {                                                                        
\
-      __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;               \
-      int _nc = dPriv->numClipRects;                                   \
-                                                                       \
-      while ( _nc-- ) {                                                        
\
-        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
-        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
-        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
-        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-#define HW_ENDCLIPLOOP()                                               \
-      }                                                                        
\
-   } while (0)
-
 #define HW_UNLOCK()                                                    
 
 
@@ -123,61 +92,26 @@
 
 /* 16 bit, RGB565 color spanline and pixel functions
  */
-#define INIT_MONO_PIXEL(p, color) \
-  p = PACK_COLOR_565( color[0], color[1], color[2] )
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
-   *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)r & 0xf8) << 8) |    \
-                                          (((int)g & 0xfc) << 3) |     \
-                                          (((int)b & 0xf8) >> 3))
-
-#define WRITE_PIXEL( _x, _y, p )                                       \
-   *(GLushort *)(buf + _x*2 + _y*pitch) = p
-
-#define READ_RGBA( rgba, _x, _y )                                      \
-   do {                                                                        
\
-      GLushort p = *(GLushort *)(read_buf + _x*2 + _y*pitch);          \
-      rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8;                                
\
-      rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc;                                
\
-      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;                                
\
-      rgba[3] = 0xff;                                                  \
-   } while (0)
-
-#define TAG(x) radeon##x##_RGB565
-#include "spantmp.h"
+#define GET_SRC_PTR(_x, _y) (read_buf + _x * 2 + _y * pitch)
+#define GET_DST_PTR(_x, _y) (     buf + _x * 2 + _y * pitch)
+#define SPANTMP_PIXEL_FMT GL_RGB
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
+
+#define TAG(x)    radeon##x##_RGB565
+#define TAG2(x,y) radeon##x##_RGB565##y
+#include "spantmp2.h"
 
 /* 32 bit, ARGB8888 color spanline and pixel functions
  */
-#undef INIT_MONO_PIXEL
-#define INIT_MONO_PIXEL(p, color) \
-  p = PACK_COLOR_8888( color[3], color[0], color[1], color[2] )
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )                       \
-do {                                                           \
-   *(GLuint *)(buf + _x*4 + _y*pitch) = ((b <<  0) |           \
-                                        (g <<  8) |            \
-                                        (r << 16) |            \
-                                        (a << 24) );           \
-} while (0)
-
-#define WRITE_PIXEL( _x, _y, p )                       \
-do {                                                   \
-   *(GLuint *)(buf + _x*4 + _y*pitch) = p;             \
-} while (0)
-
-#define READ_RGBA( rgba, _x, _y )                              \
-do {                                                           \
-   volatile GLuint *ptr = (volatile GLuint *)(read_buf + _x*4 + _y*pitch); \
-   GLuint p = *ptr;                                    \
-   rgba[0] = (p >> 16) & 0xff;                                 \
-   rgba[1] = (p >>  8) & 0xff;                                 \
-   rgba[2] = (p >>  0) & 0xff;                                 \
-   rgba[3] = (p >> 24) & 0xff;                                 \
-} while (0)
-
-#define TAG(x) radeon##x##_ARGB8888
-#include "spantmp.h"
 
+#define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * pitch)
+#define GET_DST_PTR(_x, _y) (     buf + _x * 4 + _y * pitch)
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
+
+#define TAG(x)    radeon##x##_ARGB8888
+#define TAG2(x,y) radeon##x##_ARGB8888##y
+#include "spantmp2.h"
 
 
 /* ================================================================
@@ -375,23 +309,11 @@
 
    switch ( rmesa->radeonScreen->cpp ) {
    case 2:
-      swdd->WriteRGBASpan      = radeonWriteRGBASpan_RGB565;
-      swdd->WriteRGBSpan       = radeonWriteRGBSpan_RGB565;
-      swdd->WriteMonoRGBASpan  = radeonWriteMonoRGBASpan_RGB565;
-      swdd->WriteRGBAPixels    = radeonWriteRGBAPixels_RGB565;
-      swdd->WriteMonoRGBAPixels        = radeonWriteMonoRGBAPixels_RGB565;
-      swdd->ReadRGBASpan       = radeonReadRGBASpan_RGB565;
-      swdd->ReadRGBAPixels      = radeonReadRGBAPixels_RGB565;
+      radeonInitPointers_RGB565( swdd );
       break;
 
    case 4:
-      swdd->WriteRGBASpan      = radeonWriteRGBASpan_ARGB8888;
-      swdd->WriteRGBSpan       = radeonWriteRGBSpan_ARGB8888;
-      swdd->WriteMonoRGBASpan   = radeonWriteMonoRGBASpan_ARGB8888;
-      swdd->WriteRGBAPixels     = radeonWriteRGBAPixels_ARGB8888;
-      swdd->WriteMonoRGBAPixels = radeonWriteMonoRGBAPixels_ARGB8888;
-      swdd->ReadRGBASpan       = radeonReadRGBASpan_ARGB8888;
-      swdd->ReadRGBAPixels      = radeonReadRGBAPixels_ARGB8888;
+      radeonInitPointers_ARGB8888( swdd );
       break;
 
    default:
Index: s3v/s3v_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/s3v/s3v_span.c,v
retrieving revision 1.2
diff -u -r1.2 s3v_span.c
--- s3v/s3v_span.c      27 Dec 2004 20:31:56 -0000      1.2
+++ s3v/s3v_span.c      3 Mar 2005 03:24:49 -0000
@@ -46,22 +46,6 @@
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
 
-#define CLIPPIXEL( _x, _y ) \
-       ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
-       if ( _y < miny || _y >= maxy ) { \
-               _n1 = 0, _x1 = x; \
-       } else { \
-               _n1 = _n; \
-               _x1 = _x; \
-               if ( _x1 < minx ) \
-                       _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-               if ( _x1 + _n1 >= maxx ) \
-                       n1 -= (_x1 + n1 - maxx); \
-       }
-
 #define Y_FLIP( _y )   (height - _y - 1)
 
 #if _SPANLOCK  /* OK, we lock */
@@ -83,21 +67,6 @@
 
 #endif
 
-#define HW_CLIPLOOP()                                                  \
-   do {                                                                        
\
-      __DRIdrawablePrivate *dPriv = vmesa->driDrawable;                        
\
-      int _nc = dPriv->numClipRects;                                   \
-                                                                       \
-      while ( _nc-- ) {                                                        
\
-        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
-        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
-        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
-        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-#define HW_ENDCLIPLOOP()                                               \
-      }                                                                        
\
-   } while (0)
-
 
 /* ================================================================
  * Color buffer
Index: savage/savagespan.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/savage/savagespan.c,v
retrieving revision 1.7
diff -u -r1.7 savagespan.c
--- savage/savagespan.c 21 Jan 2005 01:39:09 -0000      1.7
+++ savage/savagespan.c 3 Mar 2005 03:24:49 -0000
@@ -58,20 +58,6 @@
 
 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
-                         _y >= miny && _y < maxy)
-
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP(_y) (height - _y - 1)
 
 #define HW_LOCK()
@@ -86,21 +72,6 @@
        savageContextPtr imesa = SAVAGE_CONTEXT(ctx);   \
        char *map = imesa->readMap;
 
-#define HW_CLIPLOOP()                                          \
-  do {                                                         \
-    __DRIdrawablePrivate *dPriv = imesa->driDrawable;          \
-    int _nc = dPriv->numClipRects;                             \
-    while (_nc--) {                                            \
-       int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;                \
-       int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;        \
-       int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;                \
-       int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-
-#define HW_ENDCLIPLOOP()                       \
-    }                                          \
-  } while (0)
-
 
 /* 16 bit, 565 rgb color spanline and pixel functions
  */
Index: sis/sis_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/sis/sis_span.c,v
retrieving revision 1.6
diff -u -r1.6 sis_span.c
--- sis/sis_span.c      20 Jan 2005 13:24:08 -0000      1.6
+++ sis/sis_span.c      3 Mar 2005 03:24:49 -0000
@@ -43,6 +43,8 @@
 
 #define LOCAL_VARS                                                     \
    sisContextPtr smesa = SIS_CONTEXT(ctx);                             \
+   __DRIdrawablePrivate *dPriv = smesa->driDrawable;                   \
+   GLuint pitch = smesa->drawPitch;                                    \
    char *buf = (char *)(smesa->FbBase + smesa->drawOffset);            \
    char *read_buf = (char *)(smesa->FbBase + smesa->readOffset);       \
    GLuint p;                                                           \
@@ -50,94 +52,38 @@
 
 #define LOCAL_DEPTH_VARS                                               \
    sisContextPtr smesa = SIS_CONTEXT(ctx);                             \
+   __DRIdrawablePrivate *dPriv = smesa->driDrawable;                   \
    char *buf = smesa->depthbuffer;                                     \
 
 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS 
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
-                         _y >= miny && _y < maxy)
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
 
 #define HW_LOCK() do {} while(0);
 
-#define HW_CLIPLOOP()                                                  \
-   do {                                                                        
\
-      __DRIdrawablePrivate *dPriv = smesa->driDrawable;                        
\
-      int _nc = dPriv->numClipRects;                                   \
-                                                                       \
-      while ( _nc-- ) {                                                        
\
-        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
-        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
-        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
-        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
-
-#define HW_ENDCLIPLOOP()                                               \
-      }                                                                        
\
-   } while (0)
-
 #define HW_UNLOCK() do {} while(0);
 
 /* RGB565 */
-#define INIT_MONO_PIXEL(p, color) \
-  p = SISPACKCOLOR565( color[0], color[1], color[2] )
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
-   *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) =                   \
-                                            (((r & 0xf8) << 8) |       \
-                                            ((g & 0xfc) << 3) |        \
-                                            (b >> 3))
-
-#define WRITE_PIXEL( _x, _y, p )  \
-   *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = p
-
-#define READ_RGBA( rgba, _x, _y )                      \
-do {                                                   \
-   GLushort p = *(GLushort *)(read_buf + _x*2 + _y*smesa->readPitch);  \
-   rgba[0] = (p & 0xf800) >> 8;                                \
-   rgba[1] = (p & 0x07e0) >> 3;                                \
-   rgba[2] = (p & 0x001f) << 3;                                \
-   rgba[3] = 0xff;                                     \
-} while(0)
-
-#define TAG(x) sis##x##_565
-#include "spantmp.h"
+#define GET_SRC_PTR(_x, _y) (read_buf + _x * 2 + _y * pitch)
+#define GET_DST_PTR(_x, _y) (     buf + _x * 2 + _y * pitch)
+#define SPANTMP_PIXEL_FMT GL_RGB
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
+
+#define TAG(x)    sis##x##_RGB565
+#define TAG2(x,y) sis##x##_RGB565##y
+#include "spantmp2.h"
 
 
 /* ARGB8888 */
-#undef INIT_MONO_PIXEL
-#define INIT_MONO_PIXEL(p, color) \
-  p = SISPACKCOLOR8888( color[0], color[1], color[2], color[3] )
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )                       \
-   *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) =             \
-                                          (((a) << 24) |       \
-                                          ((r) << 16) |        \
-                                          ((g) << 8) |         \
-                                          ((b)))
-
-#define WRITE_PIXEL( _x, _y, p )  \
-   *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch)  = p
-
-#define READ_RGBA( rgba, _x, _y )                      \
-do {                                                   \
-   GLuint p = *(GLuint *)(read_buf + _x*4 + _y*smesa->readPitch);      \
-   rgba[0] = (p >> 16) & 0xff;                         \
-   rgba[1] = (p >> 8) & 0xff;                          \
-   rgba[2] = (p >> 0) & 0xff;                          \
-   rgba[3] = 0xff;                                     \
-} while(0)
-
-#define TAG(x) sis##x##_8888
-#include "spantmp.h"
+/* FIXME the old code always read back alpha as 0xff, i.e. fully opaque.
+   Was there a reason to do so ? If so that'll won't work with that 
template... */
+#define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * pitch)
+#define GET_DST_PTR(_x, _y) (     buf + _x * 4 + _y * pitch)
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
+
+#define TAG(x)    sis##x##_ARGB8888
+#define TAG2(x,y) sis##x##_ARGB8888##y
+#include "spantmp2.h"
 
 
 /* 16 bit depthbuffer functions.
@@ -283,22 +229,10 @@
    switch ( smesa->bytesPerPixel )
    {
    case 2:
-      swdd->WriteRGBASpan = sisWriteRGBASpan_565;
-      swdd->WriteRGBSpan = sisWriteRGBSpan_565;
-      swdd->WriteMonoRGBASpan = sisWriteMonoRGBASpan_565;
-      swdd->WriteRGBAPixels = sisWriteRGBAPixels_565;
-      swdd->WriteMonoRGBAPixels = sisWriteMonoRGBAPixels_565;
-      swdd->ReadRGBASpan = sisReadRGBASpan_565;
-      swdd->ReadRGBAPixels = sisReadRGBAPixels_565;
+      sisInitPointers_RGB565( swdd );
       break;
    case 4:
-      swdd->WriteRGBASpan = sisWriteRGBASpan_8888;
-      swdd->WriteRGBSpan = sisWriteRGBSpan_8888;
-      swdd->WriteMonoRGBASpan = sisWriteMonoRGBASpan_8888;
-      swdd->WriteRGBAPixels = sisWriteRGBAPixels_8888;
-      swdd->WriteMonoRGBAPixels = sisWriteMonoRGBAPixels_8888;
-      swdd->ReadRGBASpan = sisReadRGBASpan_8888;
-      swdd->ReadRGBAPixels = sisReadRGBAPixels_8888;
+      sisInitPointers_ARGB8888( swdd );
       break;
     default:
       sis_fatal_error("Bad bytesPerPixel.\n");
Index: tdfx/tdfx_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/tdfx/tdfx_span.c,v
retrieving revision 1.5
diff -u -r1.5 tdfx_span.c
--- tdfx/tdfx_span.c    2 Oct 2004 16:39:11 -0000       1.5
+++ tdfx/tdfx_span.c    3 Mar 2005 03:24:50 -0000
@@ -60,19 +60,6 @@
    (void) buf; (void) p;
 
 
-#define CLIPPIXEL( _x, _y )    ( _x >= minx && _x < maxx &&            \
-                                 _y >= miny && _y < maxy )
-
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
-   if ( _y < miny || _y >= maxy ) {                                    \
-      _n1 = 0, _x1 = x;                                                        
\
-   } else {                                                            \
-      _n1 = _n;                                                                
\
-      _x1 = _x;                                                                
\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
-   }
-
 #define Y_FLIP(_y)             (height - _y - 1)
 
 
Index: unichrome/via_span.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/unichrome/via_span.c,v
retrieving revision 1.17
diff -u -r1.17 via_span.c
--- unichrome/via_span.c        20 Jan 2005 13:24:08 -0000      1.17
+++ unichrome/via_span.c        3 Mar 2005 03:24:50 -0000
@@ -33,38 +33,9 @@
 
 #define DBG 0
 
-#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx &&    \
-                          _y >= miny && _y < maxy)
-
-
-#define CLIPSPAN(_x, _y, _n, _x1, _n1, _i)                                  \
-    if (_y < miny || _y >= maxy) {                                          \
-        _n1 = 0, _x1 = x;                                                   \
-    }                                                                       \
-    else {                                                                  \
-        _n1 = _n;                                                           \
-        _x1 = _x;                                                           \
-        if (_x1 < minx) _i += (minx -_x1), n1 -= (minx -_x1), _x1 = minx;   \
-        if (_x1 + _n1 >= maxx) n1 -= (_x1 + n1 - maxx);                     \
-   }
-
 #define Y_FLIP(_y) (height - _y - 1)
 
 #define HW_LOCK() 
-#define HW_CLIPLOOP()                                                          
\
-    do {                                                                       
\
-        __DRIdrawablePrivate *dPriv = vmesa->driDrawable;                      
\
-        int _nc = dPriv->numClipRects;                                         
\
-        while (_nc--) {                                                        
        \
-               int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;                
\
-               int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;                
\
-               int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;                
\
-               int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;        
-
-
-#define HW_ENDCLIPLOOP()                                            \
-        }                                                           \
-    } while (0)
 
 #define HW_UNLOCK()
 
Index: common/spantmp_common.h
===================================================================
 +++ common/spantmp_common.h    2005-03-02 20:08:38.000000000 +0100
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2000-2001 VA Linux Systems, Inc.
+ * (C) Copyright IBM Corporation 2004
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file spantmp_common.h
+ *
+ * common macros for span read / write functions to be used in the depth,
+ * stencil and pixel span templates.
+ */
+
+#ifndef HW_WRITE_LOCK
+#define HW_WRITE_LOCK()                HW_LOCK()
+#endif
+
+#ifndef HW_WRITE_UNLOCK
+#define HW_WRITE_UNLOCK()      HW_UNLOCK()
+#endif
+
+#ifndef HW_READ_LOCK
+#define HW_READ_LOCK()         HW_LOCK()
+#endif
+
+#ifndef HW_READ_UNLOCK
+#define HW_READ_UNLOCK()       HW_UNLOCK()
+#endif
+
+#ifndef HW_CLIPLOOP
+#define HW_CLIPLOOP()                                                  \
+   do {                                                                        
\
+      int _nc = dPriv->numClipRects;                                   \
+      while ( _nc-- ) {                                                        
\
+        int minx = dPriv->pClipRects[_nc].x1 - dPriv->x;               \
+        int miny = dPriv->pClipRects[_nc].y1 - dPriv->y;               \
+        int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x;               \
+        int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
+#endif
+
+#ifndef HW_ENDCLIPLOOP
+#define HW_ENDCLIPLOOP()                                               \
+      }                                                                        
\
+   } while (0)
+#endif
+
+#ifndef CLIPPIXEL
+#define CLIPPIXEL( _x, _y )                                            \
+   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
+#endif
+
+#ifndef CLIPSPAN
+#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )                           \
+   if ( _y < miny || _y >= maxy || _x + n < minx || _x >=maxx ) {      \
+      _n1 = 0, _x1 = x;                                                        
\
+   } else {                                                            \
+      _n1 = _n;                                                                
\
+      _x1 = _x;                                                                
\
+      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
+      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);                        
\
+   }
+#endif

Reply via email to