summaryrefslogtreecommitdiff
path: root/src/cairo-xcb-surface.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2007-05-02 10:00:22 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2007-05-04 14:29:38 +0100
commita8c8e17d845c7060286dac58b553fb717b270788 (patch)
treefd7da623d081cdd6e675d441725ef37c26fa242e /src/cairo-xcb-surface.c
parent52472b740e821dee444ede1fff041a99d344daab (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-xcb-surface.c')
-rw-r--r--src/cairo-xcb-surface.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index e8ab0fbb..304300a6 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -1577,6 +1577,39 @@ _cairo_xcb_surface_show_glyphs (void *abstract_dst,
int num_glyphs,
cairo_scaled_font_t *scaled_font);
+static cairo_bool_t
+_cairo_xcb_surface_is_similar (void *surface_a,
+ void *surface_b,
+ cairo_content_t content)
+{
+ cairo_xcb_surface_t *a = surface_a;
+ cairo_xcb_surface_t *b = surface_b;
+ xcb_render_pictforminfo_t xrender_format;
+
+ if (! _cairo_xcb_surface_same_screen (dst, src))
+ return FALSE;
+
+ /* now check that the target is a similar format */
+ xrender_format = _CAIRO_FORMAT_TO_XRENDER_FORMAT (b->dpy,
+ _cairo_format_from_content (content));
+
+ return a->xrender_format == xrender_format;
+}
+
+static cairo_status_t
+_cairo_xcb_surface_reset (void *abstract_surface)
+{
+ cairo_xcb_surface_t *surface = abstract_surface;
+ cairo_status_t status;
+
+ status = _cairo_xcb_surface_set_clip_region (surface, NULL);
+ if (status)
+ return status;
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+
/* XXX: move this to the bottom of the file, XCB and Xlib */
static const cairo_surface_backend_t cairo_xcb_surface_backend = {
@@ -1608,7 +1641,11 @@ static const cairo_surface_backend_t cairo_xcb_surface_backend = {
NULL, /* stroke */
NULL, /* fill */
_cairo_xcb_surface_show_glyphs,
- NULL /* snapshot */
+ NULL, /* snapshot */
+
+ _cairo_xcb_surface_is_similar,
+
+ _cairo_xcb_surface_reset
};
/**