[cairo] pixman BGRA support
kettenis at openbsd.org
kettenis at openbsd.org
Sun Mar 29 10:22:50 PDT 2009
> From: Soeren Sandmann <sandmann at daimi.au.dk>
> Date: 24 Mar 2009 19:34:23 +0100
>
> Mark Kettenis <kettenis at openbsd.org> writes:
>
> > Hi,
> >
> > I'm trying to make Xorg work on a Tech Source Raptor GFX-8M graphics
> > card on OpenBSD/sparc64. This card is based on the Number 9 I128-II
> > chip, which has a little-endian framebuffer, that essentially uses
> > ARGB pixel representation. However, since I'm using it on a
> > big-endian machine, the pixel representation as seen by the host CPU
> > is BGRA. As far as I can tell, the graphics hardware does not support
> > byte swapping in hardware like the ATI cards that Sun used in many of
> > their PCI framebuffers.
> >
> > The diff below adds BGRA support to pixman. I have diffs for Xrender
> > and cairo as well, that make firefox work fine (without them the most
> > obvious problem is that text seems to be drawn on a yellow
> > background).
>
> Thanks, pushed.
Thanks a lot.
With that being in, here's the code I have for cairo. There are two
issues here:
* This probably needs some #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(X,Y,Z)
sprinkled into it. Not sure what those X, Y and Z need to be though.
* To distinguish between ABGR and BGRA pixel formats my code checks
whether the LSB of masks->red_mask is set. It seems to me, that
should be the case for all ABGR formats, but I'm not absolutely sure
here.
Mark
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index e9e544d..fe6f9b7 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -77,6 +77,7 @@ _cairo_content_from_pixman_format (pixman_format_code_t pixman_format)
switch (pixman_format) {
case PIXMAN_a8r8g8b8:
case PIXMAN_a8b8g8r8:
+ case PIXMAN_b8g8r8a8:
case PIXMAN_a1r5g5b5:
case PIXMAN_a1b5g5r5:
case PIXMAN_a4r4g4b4:
@@ -91,6 +92,7 @@ _cairo_content_from_pixman_format (pixman_format_code_t pixman_format)
return CAIRO_CONTENT_COLOR_ALPHA;
case PIXMAN_x8r8g8b8:
case PIXMAN_x8b8g8r8:
+ case PIXMAN_b8g8r8x8:
case PIXMAN_r8g8b8:
case PIXMAN_b8g8r8:
case PIXMAN_r5g6b5:
@@ -171,8 +173,10 @@ _pixman_format_from_masks (cairo_format_masks_t *masks,
if (masks->red_mask) {
if (masks->red_mask > masks->blue_mask)
format_type = PIXMAN_TYPE_ARGB;
- else
+ else if (masks->red_mask & 0x1)
format_type = PIXMAN_TYPE_ABGR;
+ else
+ format_type = PIXMAN_TYPE_BGRA;
} else if (masks->alpha_mask) {
format_type = PIXMAN_TYPE_A;
} else {
@@ -232,6 +236,12 @@ _pixman_format_to_masks (pixman_format_code_t format,
masks->green_mask = MASK (g) << (r);
masks->red_mask = MASK (r);
return;
+ case PIXMAN_TYPE_BGRA:
+ masks->alpha_mask = MASK (a);
+ masks->blue_mask = MASK (b) << (masks->bpp - b);
+ masks->green_mask = MASK (g) << (masks->bpp - b - g);
+ masks->red_mask = MASK (r) << (masks->bpp - b - g - r);
+ return;
case PIXMAN_TYPE_A:
masks->alpha_mask = MASK (a);
masks->red_mask = 0;
More information about the cairo
mailing list