summaryrefslogtreecommitdiff
path: root/src/cairo-type1-fallback.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-10-21 22:48:17 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-10-22 00:53:55 +0100
commit1db8949f2baf1e620e1d5ef73a66de211420bd0a (patch)
tree23f0a27e6a92ec287be86e7f52e8d68b2aa886d3 /src/cairo-type1-fallback.c
parentb2cbbceb4ca57816a498c2c1e676b19182c34e12 (diff)
downloadcairo-1db8949f2baf1e620e1d5ef73a66de211420bd0a.tar.gz
Ensure that the scaled font is frozen for the lifetime of the scaled glyph.
After discussing the scaled font locking with Behdad, it transpired that it is not sufficient for a font to be locked for the lifetime of a scaled glyph, but that the scaled font's glyph cache must be frozen for the glyph' lifetime. If the cache is not frozen, then there is a possibility that the glyph may be evicted before the reference goes out of scope i.e. the glyph becomes invalid whilst we are trying to use it. Since the freezing of the cache is the stronger barrier, we remove the locking/unlocking of the mutex from the backends and instead move the mutex acquisition into the freeze/thaw routines. Then update the rule on acquiring glyphs to enforce that the cache is frozen and review the usage of freeze/thaw by all the backends to ensure that the cache is frozen for the lifetime of the glyph.
Diffstat (limited to 'src/cairo-type1-fallback.c')
-rw-r--r--src/cairo-type1-fallback.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 840fc7d1d..83ddc448a 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -348,7 +348,6 @@ cairo_type1_font_create_charstring (cairo_type1_font_t *font,
cairo_bool_t emit_path = TRUE;
/* This call may return CAIRO_INT_STATUS_UNSUPPORTED for bitmap fonts. */
- CAIRO_MUTEX_LOCK (font->type1_scaled_font->mutex);
status = _cairo_scaled_glyph_lookup (font->type1_scaled_font,
glyph_index,
CAIRO_SCALED_GLYPH_INFO_METRICS|
@@ -364,7 +363,6 @@ cairo_type1_font_create_charstring (cairo_type1_font_t *font,
CAIRO_SCALED_GLYPH_INFO_METRICS,
&scaled_glyph);
}
- CAIRO_MUTEX_UNLOCK (font->type1_scaled_font->mutex);
if (status)
return status;
@@ -446,18 +444,21 @@ cairo_type1_font_write_charstrings (cairo_type1_font_t *font,
"2 index /CharStrings %d dict dup begin\n",
font->scaled_font_subset->num_glyphs + 1);
+ _cairo_scaled_font_freeze_cache (font->type1_scaled_font);
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
_cairo_array_truncate (&data, 0);
/* four "random" bytes required by encryption algorithm */
status = _cairo_array_append_multiple (&data, zeros, 4);
if (status)
goto fail;
+
status = cairo_type1_font_create_charstring (font, i,
font->scaled_font_subset->glyphs[i],
CAIRO_CHARSTRING_TYPE1,
&data);
if (status)
goto fail;
+
charstring_encrypt (&data);
length = _cairo_array_num_elements (&data);
if (font->scaled_font_subset->glyph_names != NULL) {
@@ -476,6 +477,7 @@ cairo_type1_font_write_charstrings (cairo_type1_font_t *font,
}
fail:
+ _cairo_scaled_font_thaw_cache (font->type1_scaled_font);
_cairo_array_fini (&data);
return status;
}
@@ -825,6 +827,7 @@ _cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset,
goto fail1;
}
+ _cairo_scaled_font_freeze_cache (font->type1_scaled_font);
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
_cairo_array_init (&charstring, sizeof (unsigned char));
status = _cairo_array_grow_by (&charstring, 32);
@@ -842,6 +845,7 @@ _cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset,
if (status)
goto fail2;
}
+ _cairo_scaled_font_thaw_cache (font->type1_scaled_font);
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
type2_subset->widths[i] = font->widths[i];
@@ -856,6 +860,7 @@ _cairo_type2_charstrings_init (cairo_type2_charstrings_t *type2_subset,
return cairo_type1_font_destroy (font);
fail2:
+ _cairo_scaled_font_thaw_cache (font->type1_scaled_font);
_cairo_array_fini (&charstring);
_cairo_type2_charstrings_fini (type2_subset);
fail1: