xlib/shm: Propagate the last-request to the synchronous create

If we optimise away the pending frees we must be careful to propagate
the implied sync.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Limit use of the impromptu fallback pixmap for uploads

We want to avoid unnecessary readback and so only want to use the
ShmPixmap when uploading the complete surface.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Use an impromptu upload ShmSegment

Reduce the number of copies required for uploading large image data.
Ultimately we want the client to allocate the similar-image itself to
acheive zero copy, this is just an intermediate step for legacy clients.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Clear the similar image surface

The upper layers check that the surface returned to userspace is
cleared; make it so.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib: Only use CopyArea if the ShmPixmap and destination are the same depth

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Avoid using a synchronous ShmCreatePixmap if evading the readback

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Wrap the detection of shm with locking

As we access a global error variable, we need to hold a mutex against
simultaneous checking of multiple Displays. This should already be true
as we hold our display mutex to serialize initialisation, so just add an
assertion. As the client may mix use of cairo in one thread with X from
another, we need to hold the Display lock and serialise whilst
manipulating the low-level state of the Display.

Suggested-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Fix runtime checking of has-shm-pixmaps for !shm case

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Mark the ShmPixmap as active following an upload flush

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib: Drop the false optimisation of using a potentially busy shm upload pixmap

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
ft: Only use a specified font filename if its accessible

If we try to use a non-existent path, FT_New_Face returns an error.
Instead, just use fontconfig to generate a fallback pattern.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib: Move the shm cleanup from CloseDisplay to finish()

Make sure that we always detach the ShmSegments upon dispose, or else we
can trivially leak lots of memory when using serial Display connections.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
tests: Add outline-tolerance

From https://bugs.freedesktop.org/show_bug.cgi?id=53841:

"Rectangle drawn incorrectly when it has zero height
and miter limit greater than 1.414"

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
stroker: Avoid emitting a miter join for across an elided degenerate segment

Given the criteria of the rectlinear stroker that it only handles
horizontal and vertical line segments, and eliminates degenerate
segments before stroking, we must be careful not to apply a join between
two horizontal segments (for example if the intervening vertical segment
was degenerate and so elided). A miter join between two colinear
segments is empty, yet we were blissfully extending the line caps to
cover the join.

Fixes: outline-tolerance
Bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=407107
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
ft: Report FILE_NOT_FOUND if creating a font with a specified nonexistent file

If the FcPattern used to create a font specifies an exact file to use
and it does not exist we will fail much later with an ambiguous
NO_MEMORY error. As suggested by Behdad Esfahbod we should report this
back to the user so that they can take the appropriate action rather
than providing an automatic fallback.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
cairo-script: Attempt to fallback for unresolved patterns

If we fail to resolve a particular pattern, try removing a few features
from the pattern and see if we can resolve that fallback and continue on
with the trace with a close approximation.

This is then behaves very similar as if the pattern requested a specific
font that was not available on the system and so was substituted.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Use a genuine event rather than an open-ended request

Adding lots of requests without popping the replies causes xcb to
continually sort large lists of unprocessed data. Use an event instead
and regularly dequeue them.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
xlib/shm: Only check if we are expecting an event

As the XCheckWindowEvent() has the unwanted side-effect of flushing the
output queue when there is no event available (libX11 seems to be
entirely anti-performant), we need to roll our own that only checks the
already available event queue.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
gl: Remove the shader language version abstraction

Cairo only needs to support one version of the shader language API,
thanks to the dispatch table. This seems unlikely to change any time
soon. This makes the addition of new features, such as a uniform
location cache, simpler.
gl: Add a non-thread-aware mode for GL devices

GLX and EGL devices are thread-aware currently. This
is safe, but on certain GPUs can be very expensive. In
this patch, we expose a new API which turns off the
safety feature in cases where performance is a priority.