[PATCH] Add support for RENDER BGRA formats.

Michel Dänzer michel at daenzer.net
Sun Aug 2 08:00:01 PDT 2009


From: Michel Dänzer <daenzer at vmware.com>

---
 composite/compinit.c     |    4 +++-
 exa/exa_render.c         |   30 +++++++++++++++++++++++++-----
 fb/fbpict.h              |    2 ++
 hw/xfree86/xaa/xaaPict.c |   20 ++++++++++++++++----
 render/picture.c         |   36 +++++++++++++++++++++++++++++++++++-
 render/picture.h         |    3 +++
 6 files changed, 84 insertions(+), 11 deletions(-)

diff --git a/composite/compinit.c b/composite/compinit.c
index dfc3929..6159e4e 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -238,6 +238,7 @@ static CompAlternateVisual  altVisuals[] = {
     {	24,	PICT_r8g8b8 },
 #endif
     {	32,	PICT_a8r8g8b8 },
+    {	32,	PICT_b8g8r8a8 },
 };
 
 static const int NUM_COMP_ALTERNATE_VISUALS = sizeof(altVisuals) /
@@ -272,7 +273,8 @@ compAddAlternateVisual(ScreenPtr pScreen, CompScreenPtr cs,
 	return TRUE;
 
     pPictFormat = PictureMatchFormat (pScreen, alt->depth, alt->format);
-    if (!pPictFormat)
+    if (!pPictFormat ||
+	pPictFormat->direct.red != pScreen->visuals[0].offsetRed)
 	return FALSE;
 
     vid = xalloc(sizeof(VisualID));
diff --git a/exa/exa_render.c b/exa/exa_render.c
index 6566aea..3c822d1 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -54,6 +54,12 @@ static void exaCompositeFallbackPictDesc(PicturePtr pict, char *string, int n)
     case PICT_x8r8g8b8:
 	snprintf(format, 20, "XRGB8888");
 	break;
+    case PICT_b8g8r8a8:
+	snprintf(format, 20, "BGRA8888");
+	break;
+    case PICT_b8g8r8x8:
+	snprintf(format, 20, "BGRX8888");
+	break;
     case PICT_r5g6b5:
 	snprintf(format, 20, "RGB565  ");
 	break;
@@ -158,12 +164,18 @@ exaGetPixelFromRGBA(CARD32	*pixel,
 	gshift = bbits;
 	rshift = gshift + gbits;
 	ashift = rshift + rbits;
-    } else {  /* PICT_TYPE_ABGR */
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
 	rshift = 0;
 	gshift = rbits;
 	bshift = gshift + gbits;
 	ashift = bshift + bbits;
-    }
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+	bshift = PICT_FORMAT_BPP(format) - bbits;
+	gshift = bshift - gbits;
+	rshift = gshift - rbits;
+	ashift = 0;
+    } else
+	return FALSE;
 
     *pixel |=  ( blue >> (16 - bbits)) << bshift;
     *pixel |=  (  red >> (16 - rbits)) << rshift;
@@ -197,12 +209,18 @@ exaGetRGBAFromPixel(CARD32	pixel,
 	gshift = bbits;
 	rshift = gshift + gbits;
 	ashift = rshift + rbits;
-    } else {  /* PICT_TYPE_ABGR */
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
 	rshift = 0;
 	gshift = rbits;
 	bshift = gshift + gbits;
 	ashift = bshift + bbits;
-    }
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+	bshift = PICT_FORMAT_BPP(format) - bbits;
+	gshift = bshift - gbits;
+	rshift = gshift - rbits;
+	ashift = 0;
+    } else
+	return FALSE;
 
     *red = ((pixel >> rshift ) & ((1 << rbits) - 1)) << (16 - rbits);
     while (rbits < 16) {
@@ -874,11 +892,13 @@ exaComposite(CARD8	op,
     {
       if ((op == PictOpSrc &&
 	   ((pSrc->format == pDst->format) ||
+	    (pSrc->format==PICT_b8g8r8a8 && pDst->format==PICT_b8g8r8x8) ||
 	    (pSrc->format==PICT_a8r8g8b8 && pDst->format==PICT_x8r8g8b8) ||
 	    (pSrc->format==PICT_a8b8g8r8 && pDst->format==PICT_x8b8g8r8))) ||
 	  (op == PictOpOver && !pSrc->alphaMap && !pDst->alphaMap &&
 	   pSrc->format == pDst->format &&
-	   (pSrc->format==PICT_x8r8g8b8 || pSrc->format==PICT_x8b8g8r8)))
+	   (pSrc->format==PICT_x8r8g8b8 || pSrc->format==PICT_x8b8g8r8 ||
+	    pSrc->format==PICT_b8g8r8x8)))
 	{
 	    if (pSrc->pDrawable->width == 1 &&
 		pSrc->pDrawable->height == 1 &&
diff --git a/fb/fbpict.h b/fb/fbpict.h
index 0a8082e..b89f90f 100644
--- a/fb/fbpict.h
+++ b/fb/fbpict.h
@@ -95,6 +95,8 @@ fbCanGetSolid(PicturePtr pict)
     case PICT_x8r8g8b8:
     case PICT_a8b8g8r8:
     case PICT_x8b8g8r8:
+    case PICT_b8g8r8a8:
+    case PICT_b8g8r8x8:
     case PICT_r8g8b8:
     case PICT_b8g8r8:
     case PICT_r5g6b5:
diff --git a/hw/xfree86/xaa/xaaPict.c b/hw/xfree86/xaa/xaaPict.c
index 784c649..e059d3d 100644
--- a/hw/xfree86/xaa/xaaPict.c
+++ b/hw/xfree86/xaa/xaaPict.c
@@ -75,12 +75,18 @@ XAAGetPixelFromRGBA (
         gshift = bbits;
 	rshift = gshift + gbits;
 	ashift = rshift + rbits;
-    } else {  /* PICT_TYPE_ABGR */
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
         rshift = 0;
 	gshift = rbits;
 	bshift = gshift + gbits;
 	ashift = bshift + bbits;
-    }
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+	bshift = PICT_FORMAT_BPP(format) - bbits;
+	gshift = bshift - gbits;
+	rshift = gshift - rbits;
+	ashift = 0;
+    } else
+	return FALSE;
     
     *pixel |=  ( blue >> (16 - bbits)) << bshift;
     *pixel |=  (  red >> (16 - rbits)) << rshift;
@@ -116,12 +122,18 @@ XAAGetRGBAFromPixel(
         gshift = bbits;
 	rshift = gshift + gbits;
 	ashift = rshift + rbits;
-    } else {  /* PICT_TYPE_ABGR */
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
         rshift = 0;
 	gshift = rbits;
 	bshift = gshift + gbits;
 	ashift = bshift + bbits;
-    }
+    } else if(PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+	bshift = PICT_FORMAT_BPP(format) - bbits;
+	gshift = bshift - gbits;
+	rshift = gshift - rbits;
+	ashift = 0;
+    } else
+	return FALSE;
  
     *red = ((pixel >> rshift ) & ((1 << rbits) - 1)) << (16 - rbits);
     while(rbits < 16) {
diff --git a/render/picture.c b/render/picture.c
index 5f86c7c..01f4f7a 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -200,6 +200,12 @@ PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp)
     formats[nformats].format = PICT_x8r8g8b8;
     formats[nformats].depth = 32;
     nformats++;
+    formats[nformats].format = PICT_b8g8r8a8;
+    formats[nformats].depth = 32;
+    nformats++;
+    formats[nformats].format = PICT_b8g8r8x8;
+    formats[nformats].depth = 32;
+    nformats++;
 
     /* now look through the depths and visuals adding other formats */
     for (v = 0; v < pScreen->numVisuals; v++)
@@ -233,6 +239,12 @@ PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp)
 	    {
 		type = PICT_TYPE_ABGR;
 	    }
+	    else if (pVisual->offsetRed == pVisual->offsetGreen - r &&
+		     pVisual->offsetGreen == pVisual->offsetBlue - g && 
+		     pVisual->offsetBlue == bpp - b)
+	    {
+		type = PICT_TYPE_BGRA;
+	    }
 	    if (type != PICT_TYPE_OTHER)
 	    {
 		format = PICT_FORMAT(bpp, type, 0, r, g, b);
@@ -310,6 +322,8 @@ PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp)
 				      PICT_x8r8g8b8, pDepth->depth);
 		nformats = addFormat (formats, nformats,
 				      PICT_x8b8g8r8, pDepth->depth);
+		nformats = addFormat (formats, nformats,
+				      PICT_b8g8r8x8, pDepth->depth);
 	    }
 	    break;
 	}
@@ -366,6 +380,24 @@ PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp)
 	    pFormats[f].direct.red = 0;
 	    break;
 
+	case PICT_TYPE_BGRA:
+	    pFormats[f].type = PictTypeDirect;
+	    
+	    pFormats[f].direct.blueMask = Mask(PICT_FORMAT_B(format));
+	    pFormats[f].direct.blue = (PICT_FORMAT_BPP(format) - PICT_FORMAT_B(format));
+
+	    pFormats[f].direct.greenMask = Mask(PICT_FORMAT_G(format));
+	    pFormats[f].direct.green = (PICT_FORMAT_BPP(format) - PICT_FORMAT_B(format) -
+					PICT_FORMAT_G(format));
+
+	    pFormats[f].direct.redMask = Mask(PICT_FORMAT_R(format));
+	    pFormats[f].direct.red = (PICT_FORMAT_BPP(format) - PICT_FORMAT_B(format) -
+				      PICT_FORMAT_G(format) - PICT_FORMAT_R(format));
+
+	    pFormats[f].direct.alphaMask = Mask(PICT_FORMAT_A(format));
+	    pFormats[f].direct.alpha = 0;
+	    break;
+
 	case PICT_TYPE_A:
 	    pFormats[f].type = PictTypeDirect;
 
@@ -622,8 +654,10 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 		type = PICT_TYPE_A;
 	    else if (formats[n].direct.red > formats[n].direct.blue)
 		type = PICT_TYPE_ARGB;
-	    else
+	    else if (formats[n].direct.red == 0)
 		type = PICT_TYPE_ABGR;
+	    else
+		type = PICT_TYPE_BGRA;
 	    a = Ones (formats[n].direct.alphaMask);
 	    r = Ones (formats[n].direct.redMask);
 	    g = Ones (formats[n].direct.greenMask);
diff --git a/render/picture.h b/render/picture.h
index 1f90f43..dfc2d9b 100644
--- a/render/picture.h
+++ b/render/picture.h
@@ -62,6 +62,7 @@ typedef struct _Picture		*PicturePtr;
 #define PICT_TYPE_ABGR		PIXMAN_TYPE_ABGR
 #define PICT_TYPE_COLOR		PIXMAN_TYPE_COLOR
 #define PICT_TYPE_GRAY		PIXMAN_TYPE_GRAY
+#define PICT_TYPE_BGRA		PIXMAN_TYPE_BGRA
 
 #define PICT_FORMAT_COLOR(f)	PIXMAN_FORMAT_COLOR(f)
 
@@ -71,6 +72,8 @@ typedef enum _PictFormatShort {
     PICT_x8r8g8b8 =	PIXMAN_x8r8g8b8,
     PICT_a8b8g8r8 =	PIXMAN_a8b8g8r8,
     PICT_x8b8g8r8 =	PIXMAN_x8b8g8r8,
+    PICT_b8g8r8a8 =	PIXMAN_b8g8r8a8,
+    PICT_b8g8r8x8 =	PIXMAN_b8g8r8x8,
 
 /* 24bpp formats */
     PICT_r8g8b8 =	PIXMAN_r8g8b8,
-- 
1.6.3.3



More information about the xorg-devel mailing list