Module: Mesa
Branch: master
Commit: 8c1fcb823e3f39baeac633d95f5d15f3344bc62e
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8c1fcb823e3f39baeac633d95f5d15f3344bc62e

Author: Michel Dänzer <daen...@vmware.com>
Date:   Sun Aug 30 12:37:10 2009 +0200

radeon: Add more span formats for KMS on big endian.

---

 src/mesa/drivers/dri/common/spantmp2.h             |  120 ++++++++++++++++++++
 .../drivers/dri/radeon/radeon_common_context.h     |    1 +
 src/mesa/drivers/dri/radeon/radeon_fbo.c           |    9 ++-
 src/mesa/drivers/dri/radeon/radeon_span.c          |   61 +++++++++-
 4 files changed, 186 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/common/spantmp2.h 
b/src/mesa/drivers/dri/common/spantmp2.h
index 89c8157..332c917 100644
--- a/src/mesa/drivers/dri/common/spantmp2.h
+++ b/src/mesa/drivers/dri/common/spantmp2.h
@@ -82,6 +82,39 @@
       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)
 
 /**
@@ -147,6 +180,38 @@
       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)
 
 /**
@@ -202,6 +267,61 @@
      } 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
diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.h 
b/src/mesa/drivers/dri/radeon/radeon_common_context.h
index 3463b4d..09430cf 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common_context.h
+++ b/src/mesa/drivers/dri/radeon/radeon_common_context.h
@@ -96,6 +96,7 @@ typedef struct radeon_context *radeonContextPtr;
 struct radeon_renderbuffer
 {
        struct gl_renderbuffer base;
+       const struct gl_texture_format *TexFormat;
        struct radeon_bo *bo;
        unsigned int cpp;
        /* unsigned int offset; */
diff --git a/src/mesa/drivers/dri/radeon/radeon_fbo.c 
b/src/mesa/drivers/dri/radeon/radeon_fbo.c
index 6f0cc08..1a9ec6d 100644
--- a/src/mesa/drivers/dri/radeon/radeon_fbo.c
+++ b/src/mesa/drivers/dri/radeon/radeon_fbo.c
@@ -91,6 +91,7 @@ radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct 
gl_renderbuffer *rb,
    case GL_R3_G3_B2:
    case GL_RGB4:
    case GL_RGB5:
+      rrb->TexFormat = _dri_texformat_rgb565;
       rb->_ActualFormat = GL_RGB5;
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->RedBits = 5;
@@ -103,6 +104,7 @@ radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct 
gl_renderbuffer *rb,
    case GL_RGB10:
    case GL_RGB12:
    case GL_RGB16:
+      rrb->TexFormat = _dri_texformat_argb8888;
       rb->_ActualFormat = GL_RGB8;
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->RedBits = 8;
@@ -119,6 +121,7 @@ radeon_alloc_renderbuffer_storage(GLcontext * ctx, struct 
gl_renderbuffer *rb,
    case GL_RGB10_A2:
    case GL_RGBA12:
    case GL_RGBA16:
+      rrb->TexFormat = _dri_texformat_argb8888;
       rb->_ActualFormat = GL_RGBA8;
       rb->DataType = GL_UNSIGNED_BYTE;
       rb->RedBits = 8;
@@ -270,6 +273,7 @@ radeon_create_renderbuffer(GLenum format, 
__DRIdrawablePrivate *driDrawPriv)
     /* XXX format junk */
     switch (format) {
        case GL_RGB5:
+           rrb->TexFormat = _dri_texformat_rgb565;
            rrb->base._ActualFormat = GL_RGB5;
            rrb->base._BaseFormat = GL_RGBA;
            rrb->base.RedBits = 5;
@@ -278,6 +282,7 @@ radeon_create_renderbuffer(GLenum format, 
__DRIdrawablePrivate *driDrawPriv)
            rrb->base.DataType = GL_UNSIGNED_BYTE;
            break;
        case GL_RGB8:
+           rrb->TexFormat = _dri_texformat_argb8888;
            rrb->base._ActualFormat = GL_RGB8;
            rrb->base._BaseFormat = GL_RGB;
            rrb->base.RedBits = 8;
@@ -287,6 +292,7 @@ radeon_create_renderbuffer(GLenum format, 
__DRIdrawablePrivate *driDrawPriv)
            rrb->base.DataType = GL_UNSIGNED_BYTE;
            break;
        case GL_RGBA8:
+           rrb->TexFormat = _dri_texformat_argb8888;
            rrb->base._ActualFormat = GL_RGBA8;
            rrb->base._BaseFormat = GL_RGBA;
            rrb->base.RedBits = 8;
@@ -444,7 +450,8 @@ restart:
                retry++;
                goto restart;
        }
-       
+
+        rrb->TexFormat = texImage->TexFormat;
        rrb->pitch = texImage->Width * rrb->cpp;
        rrb->base.InternalFormat = rrb->base._ActualFormat;
        rrb->base.Width = texImage->Width;
diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c 
b/src/mesa/drivers/dri/radeon/radeon_span.c
index 4e100d8..c9984d1 100644
--- a/src/mesa/drivers/dri/radeon/radeon_span.c
+++ b/src/mesa/drivers/dri/radeon/radeon_span.c
@@ -41,6 +41,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
  */
 
 #include "main/glheader.h"
+#include "main/texformat.h"
 #include "swrast/swrast.h"
 
 #include "radeon_common.h"
@@ -283,6 +284,14 @@ s8z24_to_z24s8(uint32_t val)
 #define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
 #include "spantmp2.h"
 
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5
+
+#define TAG(x)    radeon##x##_ARGB1555_REV
+#define TAG2(x,y) radeon##x##_ARGB1555_REV##y
+#define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
+#include "spantmp2.h"
+
 /* 16 bit, RGBA4 color spanline and pixel functions
  */
 #define SPANTMP_PIXEL_FMT GL_BGRA
@@ -293,6 +302,14 @@ s8z24_to_z24s8(uint32_t val)
 #define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
 #include "spantmp2.h"
 
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4
+
+#define TAG(x)    radeon##x##_BGRA4444
+#define TAG2(x,y) radeon##x##_BGRA4444##y
+#define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
+#include "spantmp2.h"
+
 /* 32 bit, xRGB8888 color spanline and pixel functions
  */
 #define SPANTMP_PIXEL_FMT GL_BGRA
@@ -321,6 +338,30 @@ s8z24_to_z24s8(uint32_t val)
 } while (0)
 #include "spantmp2.h"
 
+/* 32 bit, BGRx8888 color spanline and pixel functions
+ */
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8
+
+#define TAG(x)    radeon##x##_BGRx8888
+#define TAG2(x,y) radeon##x##_BGRx8888##y
+#define GET_VALUE(_x, _y) ((*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + 
y_off)) | 0x000000ff))
+#define PUT_VALUE(_x, _y, d) { \
+   GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off );    
        \
+   *_ptr = d;                                                          \
+} while (0)
+#include "spantmp2.h"
+
+/* 32 bit, BGRA8888 color spanline and pixel functions
+ */
+#define SPANTMP_PIXEL_FMT GL_BGRA
+#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8
+
+#define TAG(x)    radeon##x##_BGRA8888
+#define TAG2(x,y) radeon##x##_BGRA8888##y
+#define GET_PTR(X,Y) radeon_ptr_4byte(rrb, (X) + x_off, (Y) + y_off)
+#include "spantmp2.h"
+
 /* ================================================================
  * Depth buffer
  */
@@ -644,13 +685,25 @@ static void radeonSetSpanFunctions(struct 
radeon_renderbuffer *rrb)
        if (rrb->base._ActualFormat == GL_RGB5) {
                radeonInitPointers_RGB565(&rrb->base);
        } else if (rrb->base._ActualFormat == GL_RGB8) {
-               radeonInitPointers_xRGB8888(&rrb->base);
+               if (rrb->TexFormat == &_mesa_texformat_argb8888_rev)
+                       radeonInitPointers_BGRx8888(&rrb->base);
+               else
+                       radeonInitPointers_xRGB8888(&rrb->base);
        } else if (rrb->base._ActualFormat == GL_RGBA8) {
-               radeonInitPointers_ARGB8888(&rrb->base);
+               if (rrb->TexFormat == &_mesa_texformat_argb8888_rev)
+                       radeonInitPointers_BGRA8888(&rrb->base);
+               else
+                       radeonInitPointers_ARGB8888(&rrb->base);
        } else if (rrb->base._ActualFormat == GL_RGBA4) {
-               radeonInitPointers_ARGB4444(&rrb->base);
+               if (rrb->TexFormat == &_mesa_texformat_argb4444_rev)
+                       radeonInitPointers_BGRA4444(&rrb->base);
+               else
+                       radeonInitPointers_ARGB4444(&rrb->base);
        } else if (rrb->base._ActualFormat == GL_RGB5_A1) {
-               radeonInitPointers_ARGB1555(&rrb->base);
+               if (rrb->TexFormat == &_mesa_texformat_argb1555_rev)
+                       radeonInitPointers_ARGB1555_REV(&rrb->base);
+               else
+                       radeonInitPointers_ARGB1555(&rrb->base);
        } else if (rrb->base._ActualFormat == GL_DEPTH_COMPONENT16) {
                radeonInitDepthPointers_z16(&rrb->base);
        } else if (rrb->base._ActualFormat == GL_DEPTH_COMPONENT24) {

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to