From 007da2f97894814eaded4d24e0481f950ca7bd00 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 14 Jan 2012 23:21:29 +0000 Subject: [PATCH] sna/gen2: Check reused source for validity Be sure the mask picture has a valid format even though it points to the same pixels as the valid source. And also be wary if the source was converted to a solid, but the mask is not. Signed-off-by: Chris Wilson --- src/sna/gen2_render.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/sna/gen2_render.c b/src/sna/gen2_render.c index b448145e..e5e5884a 100644 --- a/src/sna/gen2_render.c +++ b/src/sna/gen2_render.c @@ -198,6 +198,24 @@ gen2_get_card_format(struct sna *sna, uint32_t format) return 0; } +static uint32_t +gen2_check_format(struct sna *sna, PicturePtr p) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(i8xx_tex_formats); i++) + if (i8xx_tex_formats[i].fmt == p->format) + return true; + + if (sna->kgem.gen > 21) { + for (i = 0; i < ARRAY_SIZE(i85x_tex_formats); i++) + if (i85x_tex_formats[i].fmt == p->format) + return true; + } + + return false; +} + static uint32_t gen2_sampler_tiling_bits(uint32_t tiling) { @@ -1578,14 +1596,29 @@ reuse_source(struct sna *sna, PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y, PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y) { + uint32_t color; + + if (src_x != msk_x || src_y != msk_y) + return FALSE; + + if (src == mask) { + DBG(("%s: mask is source\n", __FUNCTION__)); + *mc = *sc; + mc->bo = kgem_bo_reference(mc->bo); + return TRUE; + } + + if (sna_picture_is_solid(mask, &color)) + return gen2_composite_solid_init(sna, mc, color); + + if (sc->is_solid) + return FALSE; + if (src->pDrawable == NULL || mask->pDrawable != src->pDrawable) return FALSE; DBG(("%s: mask reuses source drawable\n", __FUNCTION__)); - if (src_x != msk_x || src_y != msk_y) - return FALSE; - if (!sna_transform_equal(src->transform, mask->transform)) return FALSE; @@ -1598,6 +1631,9 @@ reuse_source(struct sna *sna, if (!gen2_check_filter(mask)) return FALSE; + if (!gen2_check_format(sna, mask)) + return FALSE; + DBG(("%s: reusing source channel for mask with a twist\n", __FUNCTION__));