Carl spotted that 1db894 introduced an error into text_to_glyphs() such
that following an allocation error the code would attempt to thaw an
unfrozen glyph cache, leading to an attempt to unlock an unlocked mutex -
which causes a deadlock under win32.
Quartz fonts and user fonts use an indirect font face when creating a
scaled font for the toy font face. This means that they insert a scaled
font into the font map that has a different font face to the one that is
initially searched upon. The result is that when we try to create an
identical scaled font, we fail to find the existing scaled font and
attempt to insert a duplicate into the hash table - which triggers an
assert.
In order to avoid creating duplicate fonts, we add a new method to the
font backends that allows cairo_scaled_font_create() to peek at the
font_face that will be used to actually implement the scaled font
constructor - thus we are able to use the correct font_face as part of the
hash key.
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.
Mention in the API docs that you can pass a NULL filename to
cairo_(pdf|ps|svg)_surface_create in order to construct a queryable
surface without generating any temporary files. Similarly when passing a
NULL write_func to cairo_pdf_surface_create_for_stream et al.
The current version of DirectFB does not support any filters, so set
NEAREST on the source patterns so that we can fully optimize the pattern
inside core.
If we have non-integer translation on a source pattern then we need to use
STRECTHBLIT (the core takes care to optimize NEAREST patterns to integer
translations so that this will only be used when interpolation is
required).
Allow the user to specify a NULL write_func for the output stream so that
a dummy surface can be created, for example, for querying target font
options or font extents.
Currently we do not perform any sanity checks at the user entry point and
will generate a mysterious SEGV during cairo_surface_finish() - which may
not immediately be obvious that it is due to a NULL write_func.
Principally to support creating a dummy vector surface (i.e.
cairo_ps_surface_create (NULL, 1, 1)) that can be used to determine font
extents (or target font options) before opening an output file, but also
because we currently fail to do any sanity checking at the entry point.
Simplify the error handling by only relinquishing the global
scaled_font_map mutex if we successfully insert the placeholder font. The
result is that on the error path, there are no changes to global state and
thus we can entirely skip the user-font initialisation and
re-registration.
If the surface is in error, then we cannot assume anything about the
validity of its contents other than the error status (and reference
count). This is for the cases were the surface is replaced by a nil
surface, and in future where the error surface may be replaced by a tiny
error object.
During map_glyph() we are passed a locked scaled_font for which we are
asked to add a glyph from that font into the active subsets for the
surface. This means that we eventually call scaled_glyph_lookup() to load
the glyph. But first, we attempt to find an existing an existing sub_font
for glyph, creating a new sub_font as necessary (possibly using an
entirely different unhinted scaled font). So before accessing the glyph
cache we need to make sure that we are holding the appropriate mutexes.