Re: [Mesa-dev] [RFC, PATCH] Fix 24bpp software rendering, take 2

2011-06-29 Thread Marc Pignat
This patch add the support for 24bpp in the dri/swrast implementation.

Signed-off-by: Marc Pignat marc at pignat.org
---

Hi all!

Here is a fix for https://bugs.freedesktop.org/show_bug.cgi?id=23525

This time it has been tested under kvm/qemu using:
 * cirrus emulation (truecolor 24 bits with 24 bpp)
 * vga (truecolor 24 bits with 32 bpp)

I know this is a workaround, but I think we don't need to spend
too much time for this unusual (24 bpp) mode.

Best regards


Marc


diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 07d4955..a57b327 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -100,6 +100,13 @@ XCreateDrawable(struct drisw_drawable * pdp,
   32, /* bitmap_pad */
   0); /* bytes_per_line
*/
 
+  /**
+   * swrast does not handle 24-bit depth with 24 bpp, so let X do the
+   * the conversion for us.
+   */
+  if (pdp-ximage-bits_per_pixel == 24)
+ pdp-ximage-bits_per_pixel = 32;
+
return True;
 }


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [RFC, PATCH] Fix 24bpp software rendering

2011-06-25 Thread Marc Pignat
Hi Brian

Please revert, this code does not work any more on 32bpp.

It seems that I haven't understood what the depthBits field is... 

My goal is to make it work on x11 when color depth is 24 and
bits_per_pixel is 24 (not 32).
How can I find which mode is used?

Best regards

Marc


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [RFC, PATCH] Fix 24bpp software rendering

2011-06-24 Thread Marc Pignat
This patch add the support for 24bpp in the dri/swrast implementation.

Signed-off-by: Marc Pignat m...@pignat.org

---
Hi all!

I think it is important because users of KVM or QEMU use this mode as
the default.

Here is a small list of bugs that should be fixed by this patch:
 * https://bugs.freedesktop.org/show_bug.cgi?id=23525 (sure, tested)
 * https://bugs.freedesktop.org/show_bug.cgi?id=21070 (probably)
 * https://bugs.launchpad.net/ubuntu/+source/qt4-x11/+bug/791133
 ...

Best regards


Marc

diff --git a/src/mesa/drivers/dri/swrast/swrast.c
b/src/mesa/drivers/dri/swrast/swrast.c
index 719b406..90b5ef0 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -233,10 +233,17 @@ choose_pixel_format(const struct gl_config *v)
 v-blueMask  == 0xff)
return PF_A8R8G8B8;
 else if (depth == 24
- v-redMask   == 0xff
- v-greenMask == 0x00ff00
- v-blueMask  == 0xff)
-   return PF_X8R8G8B8;
+  v-depthBits == 32
+  v-redMask   == 0xff
+  v-greenMask == 0x00ff00
+  v-blueMask  == 0xff)
+return PF_X8R8G8B8;
+else if (depth == 24
+  v-depthBits == 24
+  v-redMask   == 0xff
+  v-greenMask == 0x00ff00
+  v-blueMask  == 0xff)
+return PF_R8G8B8;
 else if (depth == 16
  v-redMask   == 0xf800
  v-greenMask == 0x07e0
@@ -344,6 +351,13 @@ swrast_new_renderbuffer(const struct gl_config
*visual, GLboolean front)
xrb-Base.DataType = GL_UNSIGNED_BYTE;
xrb-bpp = 32;
break;
+case PF_R8G8B8:
+xrb-Base.Format = MESA_FORMAT_RGB888;
+xrb-Base.InternalFormat = GL_RGB;
+xrb-Base._BaseFormat = GL_RGB;
+xrb-Base.DataType = GL_UNSIGNED_BYTE;
+xrb-bpp = 24;
+break;
 case PF_R5G6B5:
xrb-Base.Format = MESA_FORMAT_RGB565;
xrb-Base.InternalFormat = GL_RGB;
diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h
b/src/mesa/drivers/dri/swrast/swrast_priv.h
index bdb52ef..40f787f 100644
--- a/src/mesa/drivers/dri/swrast/swrast_priv.h
+++ b/src/mesa/drivers/dri/swrast/swrast_priv.h
@@ -123,6 +123,7 @@ swrast_renderbuffer(struct gl_renderbuffer *rb)
 #define PF_R5G6B5 2/** 16bpp TrueColor:  5-R, 6-G, 5-B 
bits */
 #define PF_R3G3B2 3/**  8bpp TrueColor:  3-R, 3-G, 2-B 
bits */
 #define PF_X8R8G8B8   4/** 32bpp TrueColor:  8-R, 8-G, 8-B 
bits */
+#define PF_R8G8B8 5 /** 24bpp TrueColor:  8-R, 8-G, 8-B
bits */
 
 
 /* swrast_span.c */
diff --git a/src/mesa/drivers/dri/swrast/swrast_span.c
b/src/mesa/drivers/dri/swrast/swrast_span.c
index c7d0bfd..71aafbb 100644
--- a/src/mesa/drivers/dri/swrast/swrast_span.c
+++ b/src/mesa/drivers/dri/swrast/swrast_span.c
@@ -81,6 +81,22 @@ static const GLubyte kernel[16] = {
DST[BCOMP] = *SRC  0xff
 
 
+/* 24-bit BGR */
+#define STORE_PIXEL_R8G8B8(DST, X, Y, VALUE) \
+   DST[2] = VALUE[RCOMP]; \
+   DST[1] = VALUE[GCOMP]; \
+   DST[0] = VALUE[BCOMP]
+#define STORE_PIXEL_RGB_R8G8B8(DST, X, Y, VALUE) \
+   DST[2] = VALUE[RCOMP]; \
+   DST[1] = VALUE[GCOMP]; \
+   DST[0] = VALUE[BCOMP]
+#define FETCH_PIXEL_R8G8B8(DST, SRC) \
+   DST[ACOMP] = 0xff;  \
+   DST[RCOMP] = (*SRC  16)  0xff;   \
+   DST[GCOMP] = (*SRC  8)  0xff;\
+   DST[BCOMP] = *SRC  0xff
+
+
 /* 16-bit BGR */
 #define STORE_PIXEL_R5G6B5(DST, X, Y, VALUE) \
do { \
@@ -157,6 +173,24 @@ static const GLubyte kernel[16] = {
 #include swrast/s_spantemp.h
 
 
+/* 24-bit BGR */
+#define NAME(FUNC) FUNC##_R8G8B8
+#define RB_TYPE GLubyte
+#define SPAN_VARS \
+   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+#define INIT_PIXEL_PTR(P, X, Y) \
+   GLubyte *P = (GLubyte *)xrb-Base.Data + YFLIP(xrb, Y) * xrb-pitch
+ (3*X);
+#define INC_PIXEL_PTR(P) P+=3
+#define STORE_PIXEL(DST, X, Y, VALUE) \
+   STORE_PIXEL_R8G8B8(DST, X, Y, VALUE)
+#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
+   STORE_PIXEL_RGB_R8G8B8(DST, X, Y, VALUE)
+#define FETCH_PIXEL(DST, SRC) \
+   FETCH_PIXEL_R8G8B8(DST, SRC)
+
+#include swrast/s_spantemp.h
+
+
 /* 16-bit BGR */
 #define NAME(FUNC) FUNC##_R5G6B5
 #define RB_TYPE GLubyte
@@ -229,6 +263,24 @@ static const GLubyte kernel[16] = {
 #include swrast_spantemp.h
 
 
+/* 24-bit BGR */
+#define NAME(FUNC) FUNC##_R8G8B8_front
+#define RB_TYPE GLubyte
+#define SPAN_VARS \
+   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+#define INIT_PIXEL_PTR(P, X, Y) \
+   GLubyte *P = (GLubyte *)row;
+#define INC_PIXEL_PTR(P) P+=3
+#define STORE_PIXEL(DST, X, Y, VALUE) \
+   STORE_PIXEL_R8G8B8(DST, X, Y, VALUE)
+#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
+   STORE_PIXEL_RGB_R8G8B8(DST, X, Y, VALUE)
+#define FETCH_PIXEL(DST, SRC) \
+   FETCH_PIXEL_R8G8B8(DST, SRC)
+
+#include swrast_spantemp.h
+
+
 /* 16-bit BGR */
 #define NAME(FUNC) FUNC##_R5G6B5_front
 #define RB_TYPE GLubyte
@@ -290,6