summaryrefslogtreecommitdiff
path: root/src/cairo.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-05-27 14:54:34 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-06-02 15:13:44 +0100
commitdc083ab30a5b781e205354c525ee054982364abd (patch)
treea109cec53e26a949056cc3fa6ed75782486016dd /src/cairo.c
parentfda89c56ff484a8cd33cd780e8b9396d3538284d (diff)
[cairo] Track the MRU scaled font
When observing applications two patterns emerge. The first is due to Pango, which wraps each glyph run within a context save/restore. This causes the scaled font to be evicted after every run and reloaded on the next. This is caught by the MRU slot on the cairo_scaled_font_map and prevents a relatively costly traversal of the hash table and holdovers. The second pattern is by applications that directly manage the rendering of their own glyphs. The prime example of this is gnome-terminal/vte. Here the application frequently alternates between a few scaled fonts - which requires a hash table retrieval every time. By introducing a MRU slot on the gstate we are able to directly recover the scaled font around 90% of the time. Of 110,000 set-scaled-fonts: 4,000 were setting the current font 96,000 were setting to the previous font 2,500 were recovered from the MRU on the cairo_scaled_font_map 7,500 needed a hash retrieval which compares to ~106,000 hash lookups without the additional MRU slot on the gstate. This translates to an elapsed time saving of ~5% when replaying a gnome-terminal trace using the drm backend.
Diffstat (limited to 'src/cairo.c')
-rw-r--r--src/cairo.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cairo.c b/src/cairo.c
index ddc8d4a9..3e9709fb 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -2910,6 +2910,7 @@ cairo_set_scaled_font (cairo_t *cr,
const cairo_scaled_font_t *scaled_font)
{
cairo_status_t status;
+ cairo_bool_t was_previous;
if (cr->status)
return;
@@ -2926,6 +2927,8 @@ cairo_set_scaled_font (cairo_t *cr,
if (scaled_font == cr->gstate->scaled_font)
return;
+ was_previous = scaled_font == cr->gstate->previous_scaled_font;
+
status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face);
if (unlikely (status))
goto BAIL;
@@ -2936,6 +2939,9 @@ cairo_set_scaled_font (cairo_t *cr,
_cairo_gstate_set_font_options (cr->gstate, &scaled_font->options);
+ if (was_previous)
+ cr->gstate->scaled_font = cairo_scaled_font_reference ((cairo_scaled_font_t *) scaled_font);
+
return;
BAIL: