diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-05-02 10:00:22 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-05-04 14:29:38 +0100 |
commit | a8c8e17d845c7060286dac58b553fb717b270788 (patch) | |
tree | fd7da623d081cdd6e675d441725ef37c26fa242e /src/cairo-image-surface.c | |
parent | 52472b740e821dee444ede1fff041a99d344daab (diff) |
[cairo-pattern] Cache surface for solid patterns
Original work by Jorn Baayen <jorn@openedhand.com>,
2715f2098127d04d2f9e304580a26cd0842c0e64
We use a small cache of size 16 for surfaces created for solid patterns.
This mainly helps with the X backends where we don't have to create a
pattern for every operation, so we save a lot on X traffic. Xft uses a
similar cache, so cairo's text rendering traffic with the xlib backend
now completely matches that of Xft.
The cache uses an static index variable, which itself acts like a cache of
size 1, remembering the most recently used solid pattern. So repeated
lookups for the same pattern hit immediately. If that fails, the cache is
searched linearly, and if that fails too, a new surface is created and a
random member of the cache is evicted.
A cached surface can only be reused if it is similar to the destination.
In order to check for similar surfaces a new test is introduced for the
backends to determine that the cached surface is as would be returned by
a _create_similar() call for the destination and content.
As surfaces are in general complex encapsulation of graphics state we
only return unshared cached surfaces and reset them (to clear any error
conditions and graphics state). In practice this makes little difference
to the efficacy of the cache during various benchmarks. However, in order
to transparently share solid surfaces it would be possible to implement a
COW scheme.
Cache hit rates: (hit same index + hit in cache) / lookups
cairo-perf: (42346 + 28480) / 159600 = 44.38%
gtk-theme-torturer: (3023 + 3502) / 6528 = 99.95%
gtk-perf: (8270 + 3190) / 21504 = 53.29%
This translates into a reduction of about 25% of the XRENDER traffic during
cairo-perf.
Diffstat (limited to 'src/cairo-image-surface.c')
-rw-r--r-- | src/cairo-image-surface.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 3aa4cb4fe..441947f6a 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -1071,6 +1071,19 @@ _cairo_image_surface_get_font_options (void *abstract_surface, cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON); } +static cairo_status_t +_cairo_image_surface_reset (void *abstract_surface) +{ + cairo_image_surface_t *surface = abstract_surface; + cairo_status_t status; + + status = _cairo_image_surface_set_clip_region (surface, NULL); + if (status) + return status; + + return CAIRO_STATUS_SUCCESS; +} + /** * _cairo_surface_is_image: * @surface: a #cairo_surface_t @@ -1103,7 +1116,21 @@ const cairo_surface_backend_t cairo_image_surface_backend = { NULL, /* intersect_clip_path */ _cairo_image_surface_get_extents, NULL, /* old_show_glyphs */ - _cairo_image_surface_get_font_options + _cairo_image_surface_get_font_options, + NULL, /* flush */ + NULL, /* mark_dirty_rectangle */ + NULL, //* font_fini */ + NULL, //* glyph_fini */ + + NULL, /* paint */ + NULL, /* mask */ + NULL, /* stroke */ + NULL, /* fill */ + NULL, /* show_glyphs */ + NULL, /* snapshot */ + NULL, /* is_similar */ + + _cairo_image_surface_reset }; /* A convenience function for when one needs to coerce an image |