[cairo] [Patch] Surface cache

Behdad Esfahbod behdad at behdad.org
Wed Jan 31 05:54:35 PST 2007


On Wed, 2007-01-31 at 15:43 +0200, Jorn Baayen wrote:
> Hi,
> 
> On Mon, 2007-01-29 at 16:10 -0500, Behdad Esfahbod wrote:
> > On Mon, 2007-01-29 at 15:05 -0500, Carl Worth wrote:
> > > On Mon, 29 Jan 2007 18:56:49 +0200, Jorn Baayen wrote:
> > > > Attached patch adds a simple 16-entry static cache to
> > > > _cairo_pattern_acquire_surface_for_solid(). It still needs work,
> > > however
> > > 
> > > Excellent! Thanks for providing this first step. What work is still
> > > needed here? I know Behdad had expressed interest in doing this work,
> > > so maybe he'll want to pickup your work and run with it. 
> > 
> > Excellent indeed.  And look how short the patch is!  The only things
> > that immediately come to my mind are:
> > 
> >   - Needs locking around the cache.  Then you can use a static cursor
> > too, for faster lookup (a cache of one there in itself).
> > 
> >   - With just backend comparison, does this work with two different X
> > displays?  Guess not.
> 
> Attached patch should address these two, the second by adding an
> is_similar method to cairo_surface_backend. xlib-surface implements this
> and checks that the displays match. (implementations would need to be
> written for other backends as well)

Thanks.  Looks really good.  "is_similar" is probably not the best name
here, since it may return FALSE on a surface and another one created
similar to it.  The similar surface may be a meta-surface (for SVG) or
in image surface (under certain conditions for xlib).


> >   - We have a faster random() implementation in cairo.  Lets use that.
> 
> You mean lfsr_random()? Isn't that very specialized? I see rand() being
> used elsewhere, for example in _cairo_hash_table_random_entry().

No idea really.


A small note:


+    for (i = 0; i < cache_size; i++)
+        if (_cairo_surface_is_similar (cache[i].surface, dst) &&
+            _cairo_color_equal (&cache[i].color, &pattern->color))
+            goto DONE;

I think surface_is_similar will be returning TRUE more often than
color_equal here, so reordering the test will make it faster,
theoretically.


Looks good enough to commit to me.  Xan, can you test?

> Thanks,
> 
> Jorn

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759





More information about the cairo mailing list