Drop GLcontext typedef and use struct gl_context instead
[mesa.git] / src / mesa / drivers / dri / common / spantmp2.h
index 89c815722f6a2a7e70ae6020c6c7a7454d44453c..abd79562f98490692d1f9991a8a7af96cf470144 100644 (file)
       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 = GET_VALUE(_x, _y);                                  \
+      p = p << 8 | p >> 8;                                             \
+      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)
 
 /**
       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 = GET_VALUE(_x, _y);                                  \
+      p = p << 8 | p >> 8;                                             \
+      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)
 
 /**
      } 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
+
+#elif (SPANTMP_PIXEL_FMT == GL_BGR) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
+
+/**
+ ** GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV
+ **
+ ** This is really for MESA_FORMAT_XRGB8888.  The spantmp code needs to be
+ ** kicked to the curb, and we need to just code-gen this.
+ **/
+
+#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(0xff, color[0], color[1], color[2])
+
+# define WRITE_RGBA(_x, _y, r, g, b, a)                                        \
+   PUT_VALUE(_x, _y, ((r << 16) |                                      \
+                     (g << 8) |                                        \
+                     (b << 0) |                                        \
+                     (0xff << 24)))
+
+#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__( "bswap    %0; rorl $8, %0"                \
+                               : "=r" (p) : "0" (p) );                 \
+       ((GLuint *)rgba)[0] = p | 0xff000000;                           \
+    } 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 = GET_VALUE(_x, _y);                                  \
+        *((uint32_t *) rgba) = (p << 8) | 0xff;                                \
+     } while (0)
+# else
+#  define READ_RGBA( rgba, _x, _y )                                    \
+     do {                                                              \
+        GLuint p = GET_VALUE(_x, _y);                                  \
+       rgba[0] = (p >> 16) & 0xff;                                     \
+       rgba[1] = (p >>  8) & 0xff;                                     \
+       rgba[2] = (p >>  0) & 0xff;                                     \
+       rgba[3] = 0xff;                                                 \
+     } while (0)
+# endif
+
+#elif (SPANTMP_PIXEL_FMT == GL_ALPHA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_BYTE)
+
+/**
+ ** GL_ALPHA, GL_UNSIGNED_BYTE
+ **/
+
+#ifndef GET_VALUE
+#ifndef GET_PTR
+#define GET_PTR(_x, _y) (     buf + (_x) + (_y) * pitch)
+#endif
+
+#define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y))
+#define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v)
+#endif /* GET_VALUE */
+
+# define INIT_MONO_PIXEL(p, color)                       \
+     p = color[3]
+
+# define WRITE_RGBA(_x, _y, r, g, b, a)                                 \
+   PUT_VALUE(_x, _y, a | (r & 0 /* quiet warnings */))
+
+#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
+
+#define READ_RGBA( rgba, _x, _y )                                      \
+     do {                                                              \
+        GLubyte p = GET_VALUE(_x, _y);                                 \
+       rgba[0] = 0;                                                    \
+       rgba[1] = 0;                                                    \
+       rgba[2] = 0;                                                    \
+       rgba[3] = p;                                                    \
+     } while (0)
+
 #else
 #error SPANTMP_PIXEL_FMT must be set to a valid value!
 #endif
 #include "x86/common_x86_asm.h"
 #endif
 
-static void TAG(WriteRGBASpan)( GLcontext *ctx,
+static void TAG(WriteRGBASpan)( struct gl_context *ctx,
                                 struct gl_renderbuffer *rb,
                                GLuint n, GLint x, GLint y,
                                const void *values, const GLubyte mask[] )
@@ -260,7 +503,7 @@ static void TAG(WriteRGBASpan)( GLcontext *ctx,
    HW_WRITE_UNLOCK();
 }
 
-static void TAG(WriteRGBSpan)( GLcontext *ctx,
+static void TAG(WriteRGBSpan)( struct gl_context *ctx,
                                struct gl_renderbuffer *rb,
                               GLuint n, GLint x, GLint y,
                               const void *values, const GLubyte mask[] )
@@ -299,7 +542,7 @@ static void TAG(WriteRGBSpan)( GLcontext *ctx,
    HW_WRITE_UNLOCK();
 }
 
-static void TAG(WriteRGBAPixels)( GLcontext *ctx,
+static void TAG(WriteRGBAPixels)( struct gl_context *ctx,
                                   struct gl_renderbuffer *rb,
                                   GLuint n, const GLint x[], const GLint y[],
                                   const void *values, const GLubyte mask[] )
@@ -345,7 +588,7 @@ static void TAG(WriteRGBAPixels)( GLcontext *ctx,
 }
 
 
-static void TAG(WriteMonoRGBASpan)( GLcontext *ctx,    
+static void TAG(WriteMonoRGBASpan)( struct gl_context *ctx,    
                                     struct gl_renderbuffer *rb,
                                    GLuint n, GLint x, GLint y, 
                                    const void *value, const GLubyte mask[] )
@@ -384,7 +627,7 @@ static void TAG(WriteMonoRGBASpan)( GLcontext *ctx,
 }
 
 
-static void TAG(WriteMonoRGBAPixels)( GLcontext *ctx,
+static void TAG(WriteMonoRGBAPixels)( struct gl_context *ctx,
                                       struct gl_renderbuffer *rb,
                                      GLuint n,
                                      const GLint x[], const GLint y[],
@@ -426,7 +669,7 @@ static void TAG(WriteMonoRGBAPixels)( GLcontext *ctx,
 }
 
 
-static void TAG(ReadRGBASpan)( GLcontext *ctx,
+static void TAG(ReadRGBASpan)( struct gl_context *ctx,
                                struct gl_renderbuffer *rb,
                               GLuint n, GLint x, GLint y, void *values)
 {
@@ -459,7 +702,7 @@ static void TAG(ReadRGBASpan)( GLcontext *ctx,
        (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)( GLcontext *ctx,
+static void TAG2(ReadRGBASpan,_MMX)( struct gl_context *ctx,
                                      struct gl_renderbuffer *rb,
                                      GLuint n, GLint x, GLint y, void *values)
 {
@@ -509,7 +752,7 @@ static void TAG2(ReadRGBASpan,_MMX)( GLcontext *ctx,
    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)( GLcontext *ctx,
+static void TAG2(ReadRGBASpan,_SSE2)( struct gl_context *ctx,
                                       struct gl_renderbuffer *rb,
                                       GLuint n, GLint x, GLint y,
                                       void *values)
@@ -544,7 +787,7 @@ static void TAG2(ReadRGBASpan,_SSE2)( GLcontext *ctx,
    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)( GLcontext *ctx,
+static void TAG2(ReadRGBASpan,_SSE)( struct gl_context *ctx,
                                      struct gl_renderbuffer *rb,
                                      GLuint n, GLint x, GLint y,
                                      void *values)
@@ -586,7 +829,7 @@ static void TAG2(ReadRGBASpan,_SSE)( GLcontext *ctx,
 #endif
 
 
-static void TAG(ReadRGBAPixels)( GLcontext *ctx,
+static void TAG(ReadRGBAPixels)( struct gl_context *ctx,
                                  struct gl_renderbuffer *rb,
                                 GLuint n, const GLint x[], const GLint y[],
                                 void *values )
@@ -594,7 +837,6 @@ static void TAG(ReadRGBAPixels)( GLcontext *ctx,
    HW_READ_LOCK()
       {
          GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-         GLubyte *mask = NULL; /* remove someday */
         GLint i;
         LOCAL_VARS;
 
@@ -602,23 +844,11 @@ static void TAG(ReadRGBAPixels)( GLcontext *ctx,
 
         HW_READ_CLIPLOOP()
            {
-              if (mask)
-              {
-                 for (i=0;i<n;i++)
-                    if (mask[i]) {
-                       int fy = Y_FLIP( y[i] );
-                       if (CLIPPIXEL( x[i], fy ))
-                          READ_RGBA( rgba[i], x[i], fy );
-                    }
-              }
-              else
-              {
-                 for (i=0;i<n;i++) {
-                    int fy = Y_FLIP( y[i] );
-                    if (CLIPPIXEL( x[i], fy ))
-                       READ_RGBA( rgba[i], x[i], fy );
-                 }
-              }
+               for (i=0;i<n;i++) {
+                  int fy = Y_FLIP( y[i] );
+                     if (CLIPPIXEL( x[i], fy ))
+                        READ_RGBA( rgba[i], x[i], fy );
+               }
            }
         HW_ENDCLIPLOOP();
       }