[Mesa-dev] [PATCH] st/xorg: add some support for non 32-bit color solid fills
Roland Scheidegger
sroland at vmware.com
Mon May 16 13:51:58 PDT 2011
Hmm not sure about the 8-bit case. Is that really mono and ok if we use
red channel? And I guess it doesn't make a difference if you'd use 1.0
as color[3] instead of 0 (just seems that would be more correct)?
Also, you're passing in bpp to xorg_pixel_to_float4 but don't actually
use it.
Otherwise, doesn't really look hacky to me - unless we could get other
channel ordering or something similar...
Roland
Am 16.05.2011 21:51, schrieb Marcin Slusarz:
> It's a hack, but it allows rendercheck to pass all fill and most blend tests.
> (without it all blend tests failed)
> ---
> src/gallium/state_trackers/xorg/xorg_composite.c | 70 +++++++++++++++-------
> src/gallium/state_trackers/xorg/xorg_composite.h | 6 +-
> src/gallium/state_trackers/xorg/xorg_exa.c | 16 +++++-
> 3 files changed, 66 insertions(+), 26 deletions(-)
>
> diff --git a/src/gallium/state_trackers/xorg/xorg_composite.c b/src/gallium/state_trackers/xorg/xorg_composite.c
> index d4dc84a..cadec59 100644
> --- a/src/gallium/state_trackers/xorg/xorg_composite.c
> +++ b/src/gallium/state_trackers/xorg/xorg_composite.c
> @@ -51,19 +51,53 @@ static const struct xorg_composite_blend xorg_blends[] = {
> };
>
>
> -static INLINE void
> -pixel_to_float4(Pixel pixel, float *color)
> +boolean xorg_pixel_to_float4(Pixel pixel, unsigned char bpp,
> + unsigned char depth, float *color)
> {
> CARD32 r, g, b, a;
>
> - a = (pixel >> 24) & 0xff;
> - r = (pixel >> 16) & 0xff;
> - g = (pixel >> 8) & 0xff;
> - b = (pixel >> 0) & 0xff;
> - color[0] = ((float)r) / 255.;
> - color[1] = ((float)g) / 255.;
> - color[2] = ((float)b) / 255.;
> - color[3] = ((float)a) / 255.;
> + if (depth == 32) {
> + a = (pixel >> 24) & 0xff;
> + r = (pixel >> 16) & 0xff;
> + g = (pixel >> 8) & 0xff;
> + b = (pixel >> 0) & 0xff;
> + color[0] = ((float)r) / 255.;
> + color[1] = ((float)g) / 255.;
> + color[2] = ((float)b) / 255.;
> + color[3] = ((float)a) / 255.;
> + } else if (depth == 24) {
> + r = (pixel >> 16) & 0xff;
> + g = (pixel >> 8) & 0xff;
> + b = (pixel >> 0) & 0xff;
> + color[0] = ((float)r) / 255.;
> + color[1] = ((float)g) / 255.;
> + color[2] = ((float)b) / 255.;
> + color[3] = 0;
> + } else if (depth == 8) {
> + r = pixel & 0xff;
> + color[0] = ((float)r) / 255.;
> + color[1] = 0;
> + color[2] = 0;
> + color[3] = 0;
> + } else if (depth == 16) {
> + r = (pixel >> 11) & 0x1f;
> + g = (pixel >> 5) & 0x3f;
> + b = (pixel >> 0) & 0x1f;
> + color[0] = ((float)r) / 31.;
> + color[1] = ((float)g) / 63.;
> + color[2] = ((float)b) / 31.;
> + color[3] = 0;
> + } else if (depth == 15) {
> + r = (pixel >> 10) & 0x1f;
> + g = (pixel >> 5) & 0x1f;
> + b = (pixel >> 0) & 0x1f;
> + color[0] = ((float)r) / 31.;
> + color[1] = ((float)g) / 31.;
> + color[2] = ((float)b) / 31.;
> + color[3] = 0;
> + } else
> + return FALSE;
> + return TRUE;
> }
>
> static boolean
> @@ -310,8 +344,8 @@ bind_shaders(struct exa_context *exa, int op,
> fs_traits |= FS_SOLID_FILL;
> vs_traits |= VS_SOLID_FILL;
> debug_assert(pSrcPicture->format == PICT_a8r8g8b8);
> - pixel_to_float4(pSrcPicture->pSourcePict->solidFill.color,
> - exa->solid_color);
> + xorg_pixel_to_float4(pSrcPicture->pSourcePict->solidFill.color,
> + 32, 32, exa->solid_color);
> exa->has_solid_color = TRUE;
> } else {
> debug_assert("!gradients not supported");
> @@ -526,24 +560,14 @@ void xorg_composite(struct exa_context *exa,
> }
>
> boolean xorg_solid_bind_state(struct exa_context *exa,
> - struct exa_pixmap_priv *pixmap,
> - Pixel fg)
> + struct exa_pixmap_priv *pixmap)
> {
> struct pipe_surface *dst_surf = xorg_gpu_surface(exa->pipe, pixmap);
> unsigned vs_traits, fs_traits;
> struct xorg_shader shader;
>
> - pixel_to_float4(fg, exa->solid_color);
> exa->has_solid_color = TRUE;
>
> -#if 0
> - debug_printf("Color Pixel=(%d, %d, %d, %d), RGBA=(%f, %f, %f, %f)\n",
> - (fg >> 24) & 0xff, (fg >> 16) & 0xff,
> - (fg >> 8) & 0xff, (fg >> 0) & 0xff,
> - exa->solid_color[0], exa->solid_color[1],
> - exa->solid_color[2], exa->solid_color[3]);
> -#endif
> -
> vs_traits = VS_SOLID_FILL;
> fs_traits = FS_SOLID_FILL;
>
> diff --git a/src/gallium/state_trackers/xorg/xorg_composite.h b/src/gallium/state_trackers/xorg/xorg_composite.h
> index ec71ebf..a83fec1 100644
> --- a/src/gallium/state_trackers/xorg/xorg_composite.h
> +++ b/src/gallium/state_trackers/xorg/xorg_composite.h
> @@ -22,9 +22,11 @@ void xorg_composite(struct exa_context *exa,
> int srcX, int srcY, int maskX, int maskY,
> int dstX, int dstY, int width, int height);
>
> +boolean xorg_pixel_to_float4(Pixel pixel, unsigned char bpp,
> + unsigned char depth, float *color);
> +
> boolean xorg_solid_bind_state(struct exa_context *exa,
> - struct exa_pixmap_priv *pixmap,
> - Pixel fg);
> + struct exa_pixmap_priv *pixmap);
> void xorg_solid(struct exa_context *exa,
> struct exa_pixmap_priv *pixmap,
> int x0, int y0, int x1, int y1);
> diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c
> index b072f53..18a7c10 100644
> --- a/src/gallium/state_trackers/xorg/xorg_exa.c
> +++ b/src/gallium/state_trackers/xorg/xorg_exa.c
> @@ -347,6 +347,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
> modesettingPtr ms = modesettingPTR(pScrn);
> struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
> struct exa_context *exa = ms->exa;
> + unsigned char bpp, depth;
>
> exa_debug_printf("ExaPrepareSolid(0x%x)\n", fg);
>
> @@ -371,7 +372,20 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
> XORG_FALLBACK("format %s", util_format_name(priv->tex->format));
> }
>
> - return xorg_solid_bind_state(exa, priv, fg);
> + bpp = pPixmap->drawable.bitsPerPixel;
> + depth = pPixmap->drawable.depth;
> + if (!xorg_pixel_to_float4(fg, bpp, depth, exa->solid_color))
> + XORG_FALLBACK("unsupported bpp %d / depth %d", bpp, depth);
> +
> +#if 0
> + debug_printf("Color Pixel=(%d, %d, %d, %d), RGBA=(%f, %f, %f, %f)\n",
> + (fg >> 24) & 0xff, (fg >> 16) & 0xff,
> + (fg >> 8) & 0xff, (fg >> 0) & 0xff,
> + exa->solid_color[0], exa->solid_color[1],
> + exa->solid_color[2], exa->solid_color[3]);
> +#endif
> +
> + return xorg_solid_bind_state(exa, priv);
> }
>
> static void
More information about the mesa-dev
mailing list