radeon: Fix software fallbacks with KMS on big endian.
[mesa.git] / src / mesa / drivers / dri / common / spantmp2.h
index fa737a9623f0d032a7303a1b0df68d6ca6c1642e..dd5e29f8ce6e27593a02ff2933111157babac93e 100644 (file)
  * \author Ian Romanick <idr@us.ibm.com>
  */
 
-#include "colormac.h"
+#include "main/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
 
 #if (SPANTMP_PIXEL_FMT == GL_RGB)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
 
+/**
+ ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
 #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 )                               \
-    do {                                                                \
-       GLshort * _p = (GLshort *) GET_DST_PTR(_x, _y);                  \
-       _p[0] = ((((int)r & 0xf8) << 8) | (((int)g & 0xfc) << 3) |      \
-                  (((int)b & 0xf8) >> 3));                             \
-   } while(0)
+   PUT_VALUE(_x, _y, ((((int)r & 0xf8) << 8) |                         \
+                     (((int)g & 0xfc) << 3) |                          \
+                     (((int)b & 0xf8) >> 3)))                          \
 
-#define WRITE_PIXEL( _x, _y, p )                                       \
-   do {                                                                 \
-      GLushort * _p = (GLushort *) GET_DST_PTR(_x, _y);                 \
-      _p[0] = p;                                                        \
-   } while(0)
+#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
 
 #define READ_RGBA( rgba, _x, _y )                                      \
    do {                                                                        \
-      GLushort p = *(volatile GLshort *) GET_SRC_PTR(_x, _y);           \
+      GLushort p = GET_VALUE(_x, _y);                                  \
       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)
 
+#elif (SPANTMP_PIXEL_FMT == GL_RGB)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5_REV)
+
+/**
+ ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+#define INIT_MONO_PIXEL(p, color) \
+  p = PACK_COLOR_565_REV( color[0], color[1], color[2] )
+
+#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
+   PUT_VALUE(_x, _y, PACK_COLOR_565_REV( r, g, b ))
+
+#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+   do {                                                                        \
+      GLushort p = bswap_16(GET_VALUE(_x, _y));                         \
+      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)
+
+#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4)
+
+/**
+ ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+#define INIT_MONO_PIXEL(p, color) \
+   p = PACK_COLOR_4444_REV(color[3], color[0], color[1], color[2])
+
+#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
+   PUT_VALUE(_x, _y, PACK_COLOR_4444_REV(a, r, g, b))                  \
+
+#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+   do {                                                                        \
+      GLushort p = GET_VALUE(_x, _y);                                  \
+      rgba[0] = ((p >> 0) & 0xf) * 0x11;                               \
+      rgba[1] = ((p >> 12) & 0xf) * 0x11;                              \
+      rgba[2] = ((p >> 4) & 0xf) * 0x11;                               \
+      rgba[3] = ((p >> 8) & 0xf) * 0x11;                               \
+   } while (0)
+
+
+#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4_REV)
+
+/**
+ ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+#define INIT_MONO_PIXEL(p, color) \
+   p = PACK_COLOR_4444(color[3], color[0], color[1], color[2])
+
+#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
+   PUT_VALUE(_x, _y, PACK_COLOR_4444(a, r, g, b))                      \
+
+#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+   do {                                                                        \
+      GLushort p = GET_VALUE(_x, _y);                                  \
+      rgba[0] = ((p >> 8) & 0xf) * 0x11;                               \
+      rgba[1] = ((p >> 4) & 0xf) * 0x11;                               \
+      rgba[2] = ((p >> 0) & 0xf) * 0x11;                               \
+      rgba[3] = ((p >> 12) & 0xf) * 0x11;                              \
+   } while (0)
+
+
+#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5_REV)
+
+/**
+ ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+#define INIT_MONO_PIXEL(p, color) \
+   p = PACK_COLOR_1555(color[3], color[0], color[1], color[2])
+
+#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
+   PUT_VALUE(_x, _y, PACK_COLOR_1555(a, r, g, b))                      \
+
+#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+   do {                                                                        \
+      GLushort p = GET_VALUE(_x, _y);                                  \
+      rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8;                                \
+      rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8;                                \
+      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;                                \
+      rgba[3] = ((p >> 15) & 0x1) * 0xff;                              \
+   } while (0)
+
+#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5)
+
+/**
+ ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+#define INIT_MONO_PIXEL(p, color) \
+   p = PACK_COLOR_1555_REV(color[3], color[0], color[1], color[2])
+
+#define WRITE_RGBA( _x, _y, r, g, b, a )                               \
+   PUT_VALUE(_x, _y, PACK_COLOR_1555_REV(a, r, g, b))                  \
+
+#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+   do {                                                                        \
+      GLushort p = bswap_16(GET_VALUE(_x, _y));                         \
+      rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8;                                \
+      rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8;                                \
+      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;                                \
+      rgba[3] = ((p >> 15) & 0x1) * 0xff;                              \
+   } while (0)
+
 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
 
+/**
+ ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (     buf + (_x) * 4 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
 # 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 * _p = (GLuint *) GET_DST_PTR(_x, _y);                    \
-       _p[0] = ((r << 16) | (g << 8) | (b << 0) | (a << 24));           \
-    } while(0)
+   PUT_VALUE(_x, _y, ((r << 16) |                                      \
+                     (g << 8) |                                        \
+                     (b << 0) |                                        \
+                     (a << 24)))
 
-#define WRITE_PIXEL(_x, _y, p)                                          \
-    do {                                                                \
-       GLuint * _p = (GLuint *) GET_DST_PTR(_x, _y);                    \
-       _p[0] = p;                                                       \
-    } while(0)
+#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
 
 # if defined( USE_X86_ASM )
 #  define READ_RGBA(rgba, _x, _y)                                       \
     do {                                                                \
-        GLuint p = *(volatile GLuint *) GET_SRC_PTR(_x, _y);            \
+       GLuint p = GET_VALUE(_x, _y);                                   \
        __asm__ __volatile__( "bswap    %0; rorl $8, %0"                \
-                               : "=r" (p) : "r" (p) );                 \
+                               : "=r" (p) : "0" (p) );                 \
        ((GLuint *)rgba)[0] = p;                                         \
     } while (0)
 # elif defined( MESA_BIG_ENDIAN )
      */
 #  define READ_RGBA( rgba, _x, _y )                                    \
      do {                                                              \
-        GLuint p = *(volatile GLuint *) GET_SRC_PTR(_x, _y);            \
+        GLuint p = GET_VALUE(_x, _y);                                  \
         GLuint t = p;                                                   \
         *((uint32_t *) rgba) = (t >> 24) | (p << 8);                    \
      } while (0)
 # else
 #  define READ_RGBA( rgba, _x, _y )                                    \
      do {                                                              \
-        GLuint p = *(volatile GLuint *) GET_SRC_PTR(_x, _y);            \
+        GLuint p = GET_VALUE(_x, _y);                                  \
        rgba[0] = (p >> 16) & 0xff;                                     \
        rgba[1] = (p >>  8) & 0xff;                                     \
        rgba[2] = (p >>  0) & 0xff;                                     \
      } while (0)
 # endif
 
+#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8)
+
+/**
+ ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (     buf + (_x) * 4 + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+# define INIT_MONO_PIXEL(p, color)                       \
+     p = PACK_COLOR_8888(color[2], color[1], color[0], color[3]) 
+
+# define WRITE_RGBA(_x, _y, r, g, b, a)                                 \
+   PUT_VALUE(_x, _y, ((r << 8) |                                       \
+                     (g << 16) |                                       \
+                     (b << 24) |                                       \
+                     (a << 0)))
+
+#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
+
+# if defined( USE_X86_ASM )
+#  define READ_RGBA(rgba, _x, _y)                                       \
+    do {                                                                \
+       GLuint p = GET_VALUE(_x, _y);                                   \
+       __asm__ __volatile__( "rorl $8, %0"                             \
+                               : "=r" (p) : "0" (p) );                 \
+       ((GLuint *)rgba)[0] = p;                                         \
+    } while (0)
+# elif defined( MESA_BIG_ENDIAN )
+    /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
+     * rotlwi instruction.  It also produces good code on SPARC.
+     */
+#  define READ_RGBA( rgba, _x, _y )                                    \
+     do {                                                              \
+        GLuint p = CPU_TO_LE32(GET_VALUE(_x, _y));                      \
+        GLuint t = p;                                                   \
+        *((uint32_t *) rgba) = (t >> 24) | (p << 8);                    \
+     } while (0)
+# else
+#  define READ_RGBA( rgba, _x, _y )                                    \
+     do {                                                              \
+        GLuint p = GET_VALUE(_x, _y);                                  \
+       rgba[0] = (p >>  8) & 0xff;                                     \
+       rgba[1] = (p >> 16) & 0xff;                                     \
+       rgba[2] = (p >> 24) & 0xff;                                     \
+       rgba[3] = (p >>  0) & 0xff;                                     \
+     } while (0)
+# endif
+
 #else
 #error SPANTMP_PIXEL_FMT must be set to a valid value!
 #endif
 
+
+
+/**
+ ** Assembly routines.
+ **/
+
 #if defined( USE_MMX_ASM ) || defined( USE_SSE_ASM )
 #include "x86/read_rgba_span_x86.h"
 #include "x86/common_x86_asm.h"
 #endif
 
-static void TAG(WriteRGBASpan)( const GLcontext *ctx,
+static void TAG(WriteRGBASpan)( GLcontext *ctx,
+                                struct gl_renderbuffer *rb,
                                GLuint n, GLint x, GLint y,
-                               const GLubyte rgba[][4],
-                               const GLubyte mask[] )
+                               const void *values, const GLubyte mask[] )
 {
    HW_WRITE_LOCK()
       {
+         const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
         GLint x1;
         GLint n1;
         LOCAL_VARS;
@@ -187,13 +412,14 @@ static void TAG(WriteRGBASpan)( const GLcontext *ctx,
    HW_WRITE_UNLOCK();
 }
 
-static void TAG(WriteRGBSpan)( const GLcontext *ctx,
+static void TAG(WriteRGBSpan)( GLcontext *ctx,
+                               struct gl_renderbuffer *rb,
                               GLuint n, GLint x, GLint y,
-                              const GLubyte rgb[][3],
-                              const GLubyte mask[] )
+                              const void *values, const GLubyte mask[] )
 {
    HW_WRITE_LOCK()
       {
+         const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
         GLint x1;
         GLint n1;
         LOCAL_VARS;
@@ -225,15 +451,14 @@ static void TAG(WriteRGBSpan)( const GLcontext *ctx,
    HW_WRITE_UNLOCK();
 }
 
-static void TAG(WriteRGBAPixels)( const GLcontext *ctx,
-                              GLuint n,
-                              const GLint x[],
-                              const GLint y[],
-                              const GLubyte rgba[][4],
-                              const GLubyte mask[] )
+static void TAG(WriteRGBAPixels)( GLcontext *ctx,
+                                  struct gl_renderbuffer *rb,
+                                  GLuint n, const GLint x[], const GLint y[],
+                                  const void *values, const GLubyte mask[] )
 {
    HW_WRITE_LOCK()
       {
+         const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
         GLint i;
         LOCAL_VARS;
 
@@ -272,13 +497,14 @@ static void TAG(WriteRGBAPixels)( const GLcontext *ctx,
 }
 
 
-static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx,      
+static void TAG(WriteMonoRGBASpan)( GLcontext *ctx,    
+                                    struct gl_renderbuffer *rb,
                                    GLuint n, GLint x, GLint y, 
-                                   const GLchan color[4],
-                                   const GLubyte mask[] )
+                                   const void *value, const GLubyte mask[] )
 {
    HW_WRITE_LOCK()
       {
+         const GLubyte *color = (const GLubyte *) value;
         GLint x1;
         GLint n1;
         LOCAL_VARS;
@@ -310,14 +536,16 @@ static void TAG(WriteMonoRGBASpan)( const GLcontext *ctx,
 }
 
 
-static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx,
+static void TAG(WriteMonoRGBAPixels)( GLcontext *ctx,
+                                      struct gl_renderbuffer *rb,
                                      GLuint n,
                                      const GLint x[], const GLint y[],
-                                     const GLchan color[],
+                                     const void *value,
                                      const GLubyte mask[] ) 
 {
    HW_WRITE_LOCK()
       {
+         const GLubyte *color = (const GLubyte *) value;
         GLint i;
         LOCAL_VARS;
         INIT_MONO_PIXEL(p, color);
@@ -350,12 +578,13 @@ static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx,
 }
 
 
-static void TAG(ReadRGBASpan)( const GLcontext *ctx,
-                              GLuint n, GLint x, GLint y,
-                              GLubyte rgba[][4])
+static void TAG(ReadRGBASpan)( GLcontext *ctx,
+                               struct gl_renderbuffer *rb,
+                              GLuint n, GLint x, GLint y, void *values)
 {
    HW_READ_LOCK()
       {
+         GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
         GLint x1,n1;
         LOCAL_VARS;
 
@@ -376,14 +605,15 @@ static void TAG(ReadRGBASpan)( const GLcontext *ctx,
 }
 
 
-#if defined(USE_MMX_ASM) && \
+#if defined(GET_PTR) && \
+   defined(USE_MMX_ASM) && \
    (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
        (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
     ((SPANTMP_PIXEL_FMT == GL_RGB) && \
        (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
-static void TAG2(ReadRGBASpan,_MMX)( const GLcontext *ctx,
-                              GLuint n, GLint x, GLint y,
-                              GLubyte rgba[][4])
+static void TAG2(ReadRGBASpan,_MMX)( GLcontext *ctx,
+                                     struct gl_renderbuffer *rb,
+                                     GLuint n, GLint x, GLint y, void *values)
 {
 #ifndef USE_INNER_EMMS
    /* The EMMS instruction is directly in-lined here because using GCC's
@@ -394,6 +624,7 @@ static void TAG2(ReadRGBASpan,_MMX)( const GLcontext *ctx,
 
    HW_READ_LOCK()
      {
+        GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
        GLint x1,n1;
        LOCAL_VARS;
 
@@ -407,7 +638,7 @@ static void TAG2(ReadRGBASpan,_MMX)( const GLcontext *ctx,
             CLIPSPAN(x,y,n,x1,n1,i);
 
               {
-                 const char * src = GET_SRC_PTR( x1, y );
+                 const void * src = GET_PTR( x1, y );
 #if (SPANTMP_PIXEL_FMT == GL_RGB) && \
                  (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
                  _generic_read_RGBA_span_RGB565_MMX( src, rgba[i], n1 );
@@ -426,15 +657,18 @@ static void TAG2(ReadRGBASpan,_MMX)( const GLcontext *ctx,
 #endif
 
 
-#if defined(USE_SSE_ASM) && \
+#if defined(GET_PTR) &&        \
+   defined(USE_SSE_ASM) && \
    (SPANTMP_PIXEL_FMT == GL_BGRA) && \
      (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-static void TAG2(ReadRGBASpan,_SSE2)( const GLcontext *ctx,
-                              GLuint n, GLint x, GLint y,
-                              GLubyte rgba[][4])
+static void TAG2(ReadRGBASpan,_SSE2)( GLcontext *ctx,
+                                      struct gl_renderbuffer *rb,
+                                      GLuint n, GLint x, GLint y,
+                                      void *values)
 {
    HW_READ_LOCK()
      {
+        GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
        GLint x1,n1;
        LOCAL_VARS;
 
@@ -448,7 +682,7 @@ static void TAG2(ReadRGBASpan,_SSE2)( const GLcontext *ctx,
             CLIPSPAN(x,y,n,x1,n1,i);
 
               {
-                 const char * src = GET_SRC_PTR( x1, y );
+                 const void * src = GET_PTR( x1, y );
                  _generic_read_RGBA_span_BGRA8888_REV_SSE2( src, rgba[i], n1 );
               }
          }
@@ -458,12 +692,14 @@ static void TAG2(ReadRGBASpan,_SSE2)( const GLcontext *ctx,
 }
 #endif
 
-#if defined(USE_SSE_ASM) && \
+#if defined(GET_PTR) &&        \
+   defined(USE_SSE_ASM) && \
    (SPANTMP_PIXEL_FMT == GL_BGRA) && \
      (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-static void TAG2(ReadRGBASpan,_SSE)( const GLcontext *ctx,
-                              GLuint n, GLint x, GLint y,
-                              GLubyte rgba[][4])
+static void TAG2(ReadRGBASpan,_SSE)( GLcontext *ctx,
+                                     struct gl_renderbuffer *rb,
+                                     GLuint n, GLint x, GLint y,
+                                     void *values)
 {
 #ifndef USE_INNER_EMMS
    /* The EMMS instruction is directly in-lined here because using GCC's
@@ -474,6 +710,7 @@ static void TAG2(ReadRGBASpan,_SSE)( const GLcontext *ctx,
 
    HW_READ_LOCK()
      {
+        GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
        GLint x1,n1;
        LOCAL_VARS;
 
@@ -487,7 +724,7 @@ static void TAG2(ReadRGBASpan,_SSE)( const GLcontext *ctx,
             CLIPSPAN(x,y,n,x1,n1,i);
 
               {
-                 const char * src = GET_SRC_PTR( x1, y );
+                 const void * src = GET_PTR( x1, y );
                  _generic_read_RGBA_span_BGRA8888_REV_SSE( src, rgba[i], n1 );
               }
          }
@@ -501,12 +738,15 @@ static void TAG2(ReadRGBASpan,_SSE)( const GLcontext *ctx,
 #endif
 
 
-static void TAG(ReadRGBAPixels)( const GLcontext *ctx,
+static void TAG(ReadRGBAPixels)( GLcontext *ctx,
+                                 struct gl_renderbuffer *rb,
                                 GLuint n, const GLint x[], const GLint y[],
-                                GLubyte rgba[][4], const GLubyte mask[] )
+                                void *values )
 {
    HW_READ_LOCK()
       {
+         GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
+         GLubyte *mask = NULL; /* remove someday */
         GLint i;
         LOCAL_VARS;
 
@@ -537,21 +777,22 @@ static void TAG(ReadRGBAPixels)( const GLcontext *ctx,
    HW_READ_UNLOCK();
 }
 
-static void TAG(InitPointers)(struct swrast_device_driver *swdd)
+static void TAG(InitPointers)(struct gl_renderbuffer *rb)
 {
-   swdd->WriteRGBASpan = TAG(WriteRGBASpan);
-   swdd->WriteRGBSpan = TAG(WriteRGBSpan);
-   swdd->WriteMonoRGBASpan = TAG(WriteMonoRGBASpan);
-   swdd->WriteRGBAPixels = TAG(WriteRGBAPixels);
-   swdd->WriteMonoRGBAPixels = TAG(WriteMonoRGBAPixels);
-   swdd->ReadRGBAPixels = TAG(ReadRGBAPixels);
-
+   rb->PutRow = TAG(WriteRGBASpan);
+   rb->PutRowRGB = TAG(WriteRGBSpan);
+   rb->PutMonoRow = TAG(WriteMonoRGBASpan);
+   rb->PutValues = TAG(WriteRGBAPixels);
+   rb->PutMonoValues = TAG(WriteMonoRGBAPixels);
+   rb->GetValues = TAG(ReadRGBAPixels);
+
+#if defined(GET_PTR)
 #if defined(USE_SSE_ASM) && \
    (SPANTMP_PIXEL_FMT == GL_BGRA) && \
      (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
    if ( cpu_has_xmm2 ) {
-      if (DBG) fprintf( stderr, "Using %s version of ReadRGBASpan\n", "SSE2" );
-      swdd->ReadRGBASpan = TAG2(ReadRGBASpan, _SSE2);
+      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE2" );
+      rb->GetRow = TAG2(ReadRGBASpan, _SSE2);
    }
    else
 #endif
@@ -559,8 +800,8 @@ static void TAG(InitPointers)(struct swrast_device_driver *swdd)
    (SPANTMP_PIXEL_FMT == GL_BGRA) && \
      (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
    if ( cpu_has_xmm ) {
-      if (DBG) fprintf( stderr, "Using %s version of ReadRGBASpan\n", "SSE" );
-      swdd->ReadRGBASpan = TAG2(ReadRGBASpan, _SSE);
+      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE" );
+      rb->GetRow = TAG2(ReadRGBASpan, _SSE);
    }
    else
 #endif
@@ -570,14 +811,15 @@ static void TAG(InitPointers)(struct swrast_device_driver *swdd)
     ((SPANTMP_PIXEL_FMT == GL_RGB) && \
        (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
    if ( cpu_has_mmx ) {
-      if (DBG) fprintf( stderr, "Using %s version of ReadRGBASpan\n", "MMX" );
-      swdd->ReadRGBASpan = TAG2(ReadRGBASpan, _MMX);
+      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "MMX" );
+      rb->GetRow = TAG2(ReadRGBASpan, _MMX);
    }
    else
 #endif
+#endif /* GET_PTR */
    {
-      if (DBG) fprintf( stderr, "Using %s version of ReadRGBASpan\n", "C" );
-      swdd->ReadRGBASpan = TAG(ReadRGBASpan);
+      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "C" );
+      rb->GetRow = TAG(ReadRGBASpan);
    }
 
 }
@@ -589,7 +831,8 @@ static void TAG(InitPointers)(struct swrast_device_driver *swdd)
 #undef READ_RGBA
 #undef TAG
 #undef TAG2
-#undef GET_SRC_PTR
-#undef GET_DST_PTR
+#undef GET_VALUE
+#undef PUT_VALUE
+#undef GET_PTR
 #undef SPANTMP_PIXEL_FMT
 #undef SPANTMP_PIXEL_TYPE