diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2012-04-03 12:34:24 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2012-04-03 12:36:22 +0100 |
commit | 04851e4210d2d71542359c14d4b68d0851b36326 (patch) | |
tree | 6b905b56e82f8b70eac86e9b059db75eb3f02f96 | |
parent | 87a672dafd9d6f47f31b77b406b7f0fb2b4030ac (diff) |
sna/gen3: Convert the clear-color from picture->format to a8r8g8b8
The shaders treat colours as an argb value, however the clear color is
stored in the pixmap's native format (a8, r5g6b5, x8r8g8b8 etc). So
before using the value of the clear color as a solid we need to convert
it into the a8r8g8b8 format.
Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48204
Reported-by: Paul Neumann <paul104x@yahoo.de>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47308
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/sna/gen3_render.c | 53 | ||||
-rw-r--r-- | src/sna/sna_blt.c | 39 | ||||
-rw-r--r-- | src/sna/sna_render.h | 6 | ||||
-rw-r--r-- | src/sna/sna_render_inline.h | 25 |
4 files changed, 69 insertions, 54 deletions
diff --git a/src/sna/gen3_render.c b/src/sna/gen3_render.c index 0478709f..ca3d1414 100644 --- a/src/sna/gen3_render.c +++ b/src/sna/gen3_render.c @@ -2080,7 +2080,7 @@ gen3_init_solid(struct sna_composite_channel *channel, uint32_t color) channel->u.gen3.type = SHADER_WHITE; channel->bo = NULL; - channel->is_opaque = (color & 0xff000000) == 0xff000000; + channel->is_opaque = (color >> 24) == 0xff; channel->is_affine = 1; channel->alpha_fixup = 0; channel->rb_reversed = 0; @@ -2303,6 +2303,8 @@ gen3_composite_picture(struct sna *sna, switch (source->type) { case SourcePictTypeSolidFill: + DBG(("%s: solid fill [%08x], format %x\n", + __FUNCTION__, source->solidFill.color, picture->format)); ret = gen3_init_solid(channel, source->solidFill.color); break; @@ -2334,11 +2336,15 @@ gen3_composite_picture(struct sna *sna, x, y, w, h, dst_x, dst_y); } - if (sna_picture_is_solid(picture, &color)) + if (sna_picture_is_solid(picture, &color)) { + DBG(("%s: solid drawable [%08x]\n", __FUNCTION__, color)); return gen3_init_solid(channel, color); + } - if (sna_picture_is_clear(picture, x, y, w, h, &color)) - return gen3_init_solid(channel, color); + if (sna_picture_is_clear(picture, x, y, w, h, &color)) { + DBG(("%s: clear drawable [%08x]\n", __FUNCTION__, color)); + return gen3_init_solid(channel, color_convert(color, picture->format, PICT_a8r8g8b8)); + } if (!gen3_check_repeat(picture)) return sna_render_picture_fixup(sna, picture, channel, @@ -2517,11 +2523,16 @@ gen3_composite_set_target(struct sna *sna, return TRUE; } +static inline uint8_t +mul_8_8(uint8_t a, uint8_t b) +{ + uint16_t t = a * (uint16_t)b + 0x7f; + return ((t >> 8) + t) >> 8; +} + static inline uint8_t multa(uint32_t s, uint32_t m, int shift) { - s = (s >> shift) & 0xff; - m >>= 24; - return (s * m) >> 8; + return mul_8_8((s >> shift) & 0xff, m >> 24) << shift; } static inline bool is_constant_ps(uint32_t type) @@ -2894,33 +2905,31 @@ gen3_render_composite(struct sna *sna, } else { if (tmp->mask.is_opaque) { tmp->mask.u.gen3.type = SHADER_NONE; - tmp->has_component_alpha = FALSE; } else if (is_constant_ps(tmp->src.u.gen3.type) && is_constant_ps(tmp->mask.u.gen3.type)) { - uint32_t a,r,g,b; + uint32_t v; - a = multa(tmp->src.u.gen3.mode, + v = multa(tmp->src.u.gen3.mode, tmp->mask.u.gen3.mode, 24); - r = multa(tmp->src.u.gen3.mode, - tmp->mask.u.gen3.mode, - 16); - g = multa(tmp->src.u.gen3.mode, - tmp->mask.u.gen3.mode, - 8); - b = multa(tmp->src.u.gen3.mode, - tmp->mask.u.gen3.mode, - 0); + v != multa(tmp->src.u.gen3.mode, + tmp->mask.u.gen3.mode, + 16); + v != multa(tmp->src.u.gen3.mode, + tmp->mask.u.gen3.mode, + 8); + v != multa(tmp->src.u.gen3.mode, + tmp->mask.u.gen3.mode, + 0); DBG(("%s: combining constant source/mask: %x x %x -> %x\n", __FUNCTION__, tmp->src.u.gen3.mode, tmp->mask.u.gen3.mode, - a << 24 | r << 16 | g << 8 | b)); + v)); tmp->src.u.gen3.type = SHADER_CONSTANT; - tmp->src.u.gen3.mode = - a << 24 | r << 16 | g << 8 | b; + tmp->src.u.gen3.mode = v; tmp->mask.u.gen3.type = SHADER_NONE; } diff --git a/src/sna/sna_blt.c b/src/sna/sna_blt.c index e7a6182f..a81a1454 100644 --- a/src/sna/sna_blt.c +++ b/src/sna/sna_blt.c @@ -476,13 +476,13 @@ static void sna_blt_copy_one(struct sna *sna, kgem->nbatch += 8; } -static Bool -get_rgba_from_pixel(uint32_t pixel, - uint16_t *red, - uint16_t *green, - uint16_t *blue, - uint16_t *alpha, - uint32_t format) +Bool +sna_get_rgba_from_pixel(uint32_t pixel, + uint16_t *red, + uint16_t *green, + uint16_t *blue, + uint16_t *alpha, + uint32_t format) { int rbits, bbits, gbits, abits; int rshift, bshift, gshift, ashift; @@ -607,31 +607,6 @@ _sna_get_pixel_from_rgba(uint32_t * pixel, return TRUE; } -static uint32_t -color_convert(uint32_t pixel, - uint32_t src_format, - uint32_t dst_format) -{ - DBG(("%s: src=%08x [%08x]\n", __FUNCTION__, pixel, src_format)); - - if (src_format != dst_format) { - uint16_t red, green, blue, alpha; - - if (!get_rgba_from_pixel(pixel, - &red, &green, &blue, &alpha, - src_format)) - return 0; - - if (!sna_get_pixel_from_rgba(&pixel, - red, green, blue, alpha, - dst_format)) - return 0; - } - - DBG(("%s: dst=%08x [%08x]\n", __FUNCTION__, pixel, dst_format)); - return pixel; -} - uint32_t sna_rgba_for_color(uint32_t color, int depth) { diff --git a/src/sna/sna_render.h b/src/sna/sna_render.h index 73ef5680..9c49281d 100644 --- a/src/sna/sna_render.h +++ b/src/sna/sna_render.h @@ -485,6 +485,12 @@ sna_render_get_gradient(struct sna *sna, uint32_t sna_rgba_for_color(uint32_t color, int depth); uint32_t sna_rgba_to_color(uint32_t rgba, uint32_t format); +Bool sna_get_rgba_from_pixel(uint32_t pixel, + uint16_t *red, + uint16_t *green, + uint16_t *blue, + uint16_t *alpha, + uint32_t format); Bool sna_picture_is_solid(PicturePtr picture, uint32_t *color); void no_render_init(struct sna *sna); diff --git a/src/sna/sna_render_inline.h b/src/sna/sna_render_inline.h index 956e2aa2..03e1969d 100644 --- a/src/sna/sna_render_inline.h +++ b/src/sna/sna_render_inline.h @@ -190,4 +190,29 @@ sna_render_reduce_damage(struct sna_composite_op *op, } } +inline static uint32_t +color_convert(uint32_t pixel, + uint32_t src_format, + uint32_t dst_format) +{ + DBG(("%s: src=%08x [%08x]\n", __FUNCTION__, pixel, src_format)); + + if (src_format != dst_format) { + uint16_t red, green, blue, alpha; + + if (!sna_get_rgba_from_pixel(pixel, + &red, &green, &blue, &alpha, + src_format)) + return 0; + + if (!sna_get_pixel_from_rgba(&pixel, + red, green, blue, alpha, + dst_format)) + return 0; + } + + DBG(("%s: dst=%08x [%08x]\n", __FUNCTION__, pixel, dst_format)); + return pixel; +} + #endif /* SNA_RENDER_INLINE_H */ |