diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-09-12 10:37:24 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-09-12 10:56:29 +0100 |
commit | c2e19987c333de31b258a3af37a2ed1f63ef949a (patch) | |
tree | 8b4b310e2438454a97ac8c1a21563bbfa0adab7d /src/sna/sna_gradient.c | |
parent | 04c5a3df02f6f40a904ff4edb927ae6ff0ce6408 (diff) |
sna: Provide a direct lookup cache of alpha values
To reflect recent changes in cairo.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/sna/sna_gradient.c')
-rw-r--r-- | src/sna/sna_gradient.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/sna/sna_gradient.c b/src/sna/sna_gradient.c index 6b85b100..20850c8f 100644 --- a/src/sna/sna_gradient.c +++ b/src/sna/sna_gradient.c @@ -260,8 +260,11 @@ sna_render_get_solid(struct sna *sna, uint32_t color) struct sna_solid_cache *cache = &sna->render.solid_cache; unsigned int i; - if (color == 0) { - DBG(("%s(clear)\n", __FUNCTION__)); + if ((color & 0xffffff) == 0) /* alpha only */ + return kgem_bo_reference(sna->render.alpha_cache.bo[color>>24]); + + if (color == 0xffffffff) { + DBG(("%s(white)\n", __FUNCTION__)); return kgem_bo_reference(cache->bo[0]); } @@ -302,6 +305,27 @@ done: return kgem_bo_reference(cache->bo[i]); } +static Bool sna_alpha_cache_init(struct sna *sna) +{ + struct sna_alpha_cache *cache = &sna->render.alpha_cache; + uint32_t color[256]; + int i; + + cache->cache_bo = kgem_create_linear(&sna->kgem, sizeof(color)); + if (!cache->cache_bo) + return FALSE; + + for (i = 0; i < 256; i++) { + color[i] = i << 24; + cache->bo[i] = kgem_create_proxy(cache->cache_bo, + sizeof(uint32_t)*i, + sizeof(uint32_t)); + cache->bo[i]->pitch = 4; + } + kgem_bo_write(&sna->kgem, cache->cache_bo, color, sizeof(color)); + return TRUE; +} + static Bool sna_solid_cache_init(struct sna *sna) { struct sna_solid_cache *cache = &sna->render.solid_cache; @@ -311,6 +335,7 @@ static Bool sna_solid_cache_init(struct sna *sna) if (!cache->cache_bo) return FALSE; + cache->color[0] = 0xffffffff; cache->bo[0] = kgem_create_proxy(cache->cache_bo, 0, sizeof(uint32_t)); cache->bo[0]->pitch = 4; cache->size = 1; @@ -320,13 +345,26 @@ static Bool sna_solid_cache_init(struct sna *sna) Bool sna_gradients_create(struct sna *sna) { - return sna_solid_cache_init(sna); + if (!sna_alpha_cache_init(sna)) + return FALSE; + + if (!sna_solid_cache_init(sna)) + return FALSE; + + return TRUE; } void sna_gradients_close(struct sna *sna) { int i; + for (i = 0; i < 256; i++) { + if (sna->render.alpha_cache.bo[i]) + kgem_bo_destroy(&sna->kgem, sna->render.alpha_cache.bo[i]); + } + if (sna->render.alpha_cache.cache_bo) + kgem_bo_destroy(&sna->kgem, sna->render.alpha_cache.cache_bo); + if (sna->render.solid_cache.cache_bo) kgem_bo_destroy(&sna->kgem, sna->render.solid_cache.cache_bo); for (i = 0; i < sna->render.solid_cache.size; i++) { |