aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/cairo
diff options
context:
space:
mode:
authorDenys Dmytriyenko <denis@denix.org>2009-03-17 14:32:59 -0400
committerDenys Dmytriyenko <denis@denix.org>2009-03-17 14:32:59 -0400
commit709c4d66e0b107ca606941b988bad717c0b45d9b (patch)
tree37ee08b1eb308f3b2b6426d5793545c38396b838 /recipes/cairo
parentfa6cd5a3b993f16c27de4ff82b42684516d433ba (diff)
downloadopenembedded-709c4d66e0b107ca606941b988bad717c0b45d9b.tar.gz
rename packages/ to recipes/ per earlier agreement
See links below for more details: http://thread.gmane.org/gmane.comp.handhelds.openembedded/21326 http://thread.gmane.org/gmane.comp.handhelds.openembedded/21816 Signed-off-by: Denys Dmytriyenko <denis@denix.org> Acked-by: Mike Westerhof <mwester@dls.net> Acked-by: Philip Balister <philip@balister.org> Acked-by: Khem Raj <raj.khem@gmail.com> Acked-by: Marcin Juszkiewicz <hrw@openembedded.org> Acked-by: Koen Kooi <koen@openembedded.org> Acked-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
Diffstat (limited to 'recipes/cairo')
-rw-r--r--recipes/cairo/cairo-1.2.4/0001-Add-autoconf-macro-AX_C_FLOAT_WORDS_BIGENDIAN.diff103
-rw-r--r--recipes/cairo/cairo-1.2.4/0002-Change-_cairo_fixed_from_double-to-use-the-magic-number-technique.diff79
-rw-r--r--recipes/cairo/cairo-1.2.4/0003-Add-new-perf-test-pattern_create_radial.diff164
-rw-r--r--recipes/cairo/cairo-1.3.4/configure.in_requires_pkg-config-0.15.diff13
-rw-r--r--recipes/cairo/cairo-1.4.10/stats.patch33
-rw-r--r--recipes/cairo/cairo-1.4.14/0001-Fix-for-a-memory-leak-in-pixman.patch32
-rw-r--r--recipes/cairo/cairo-1.4.4/cairo-workqueue.patch2148
-rw-r--r--recipes/cairo/cairo-1.6.4/configure_fix.patch70
-rw-r--r--recipes/cairo/cairo-directfb-1.6.4/configure_fix.patch70
-rw-r--r--recipes/cairo/cairo-directfb_1.4.8.bb18
-rw-r--r--recipes/cairo/cairo-directfb_1.6.4.bb17
-rw-r--r--recipes/cairo/cairo-fpu.inc6
-rw-r--r--recipes/cairo/cairo.inc15
-rw-r--r--recipes/cairo/cairo_1.2.4.bb17
-rw-r--r--recipes/cairo/cairo_1.4.10.bb9
-rw-r--r--recipes/cairo/cairo_1.4.14.bb9
-rw-r--r--recipes/cairo/cairo_1.4.8.bb6
-rw-r--r--recipes/cairo/cairo_1.6.4.bb9
-rw-r--r--recipes/cairo/cairo_1.7.6.bb9
-rw-r--r--recipes/cairo/cairo_1.8.0.bb6
-rw-r--r--recipes/cairo/cairo_git.bb24
-rw-r--r--recipes/cairo/cairomm_1.2.4.bb9
-rw-r--r--recipes/cairo/files/cairo-surface-cache-3.patch371
-rw-r--r--recipes/cairo/files/cairo_directfb_is_similar-typo.patch11
-rw-r--r--recipes/cairo/libsvg-0.1.4/configure_fix.patch22
-rw-r--r--recipes/cairo/libsvg-0.1.4/gcc4_and_expat.patch19
-rw-r--r--recipes/cairo/libsvg-cairo/libsvg-cairo-libtool.diff27
-rw-r--r--recipes/cairo/libsvg-cairo_0.1.5.bb13
-rw-r--r--recipes/cairo/libsvg-cairo_0.1.6.bb13
-rw-r--r--recipes/cairo/libsvg-cairo_20050601.bb18
-rw-r--r--recipes/cairo/libsvg-cairo_cvs.bb15
-rw-r--r--recipes/cairo/libsvg_0.1.4.bb18
-rw-r--r--recipes/cairo/libsvg_cvs.bb17
-rw-r--r--recipes/cairo/xsvg_cvs.bb18
34 files changed, 3428 insertions, 0 deletions
diff --git a/recipes/cairo/cairo-1.2.4/0001-Add-autoconf-macro-AX_C_FLOAT_WORDS_BIGENDIAN.diff b/recipes/cairo/cairo-1.2.4/0001-Add-autoconf-macro-AX_C_FLOAT_WORDS_BIGENDIAN.diff
new file mode 100644
index 0000000000..90718d4976
--- /dev/null
+++ b/recipes/cairo/cairo-1.2.4/0001-Add-autoconf-macro-AX_C_FLOAT_WORDS_BIGENDIAN.diff
@@ -0,0 +1,103 @@
+From nobody Mon Sep 17 00:00:00 2001
+From: Dan Amelang <dan@amelang.net>
+Date: Sun Oct 29 21:30:08 2006 -0800
+Subject: [PATCH] Add autoconf macro AX_C_FLOAT_WORDS_BIGENDIAN
+
+The symbol that this macro defines (FLOAT_WORDS_BIGENDIAN) can be used
+to make double arithmetic tricks portable.
+
+---
+
+ acinclude.m4 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ configure.in | 1 +
+ 2 files changed, 66 insertions(+), 0 deletions(-)
+
+3231d91b59a6c2e1c40bbaa8b143694b6c693662
+diff --git a/acinclude.m4 b/acinclude.m4
+index af73800..a0eb13a 100644
+--- a/acinclude.m4
++++ b/acinclude.m4
+@@ -51,3 +51,68 @@ ifelse([$1],[],,
+ AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)
+ AM_CONDITIONAL(GTK_DOC_USE_LIBTOOL, test -n "$LIBTOOL")
+ ])
++
++# AX_C_FLOAT_WORDS_BIGENDIAN ([ACTION-IF-TRUE], [ACTION-IF-FALSE],
++# [ACTION-IF-UNKNOWN])
++#
++# Checks the ordering of words within a multi-word float. This check
++# is necessary because on some systems (e.g. certain ARM systems), the
++# float word ordering can be different from the byte ordering. In a
++# multi-word float context, "big-endian" implies that the word containing
++# the sign bit is found in the memory location with the lowest address.
++# This implemenation was inspired by the AC_C_BIGENDIAN macro in autoconf.
++# -------------------------------------------------------------------------
++AC_DEFUN([AX_C_FLOAT_WORDS_BIGENDIAN],
++ [AC_CACHE_CHECK(whether float word ordering is bigendian,
++ ax_cv_c_float_words_bigendian, [
++
++# The endianess is detected by first compiling C code that contains a special
++# double float value, then grepping the resulting object file for certain
++# strings of ascii values. The double is specially crafted to have a
++# binary representation that corresponds with a simple string. In this
++# implementation, the string "noonsees" was selected because the individual
++# word values ("noon" and "sees") are palindromes, thus making this test
++# byte-order agnostic. If grep finds the string "noonsees" in the object
++# file, the target platform stores float words in big-endian order. If grep
++# finds "seesnoon", float words are in little-endian order. If neither value
++# is found, the user is instructed to specify the ordering.
++
++ax_cv_c_float_words_bigendian=unknown
++AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
++
++double d = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0;
++
++]])], [
++
++if grep noonsees conftest.$ac_objext >/dev/null ; then
++ ax_cv_c_float_words_bigendian=yes
++fi
++if grep seesnoon conftest.$ac_objext >/dev/null ; then
++ if test "$ax_cv_c_float_words_bigendian" = unknown; then
++ ax_cv_c_float_words_bigendian=no
++ else
++ ax_cv_c_float_words_bigendian=unknown
++ fi
++fi
++
++])])
++
++case $ax_cv_c_float_words_bigendian in
++ yes)
++ m4_default([$1],
++ [AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1,
++ [Define to 1 if your system stores words within floats
++ with the most significant word first])]) ;;
++ no)
++ $2 ;;
++ *)
++ m4_default([$3],
++ [AC_MSG_ERROR([
++
++Unknown float word ordering. You need to manually preset
++ax_cv_c_float_words_bigendian=no (or yes) according to your system.
++
++ ])]) ;;
++esac
++
++])# AX_C_FLOAT_WORDS_BIGENDIAN
+diff --git a/configure.in b/configure.in
+index 2d2bf9f..797c7ce 100644
+--- a/configure.in
++++ b/configure.in
+@@ -55,6 +55,7 @@ AC_PROG_CPP
+ AC_PROG_LIBTOOL dnl required version (1.4) DON'T REMOVE!
+ AC_STDC_HEADERS
+ AC_C_BIGENDIAN
++AX_C_FLOAT_WORDS_BIGENDIAN
+
+ dnl ===========================================================================
+ dnl === Local macros
+--
+1.2.6
+
diff --git a/recipes/cairo/cairo-1.2.4/0002-Change-_cairo_fixed_from_double-to-use-the-magic-number-technique.diff b/recipes/cairo/cairo-1.2.4/0002-Change-_cairo_fixed_from_double-to-use-the-magic-number-technique.diff
new file mode 100644
index 0000000000..56d8b7e99a
--- /dev/null
+++ b/recipes/cairo/cairo-1.2.4/0002-Change-_cairo_fixed_from_double-to-use-the-magic-number-technique.diff
@@ -0,0 +1,79 @@
+From nobody Mon Sep 17 00:00:00 2001
+From: Dan Amelang <dan@amelang.net>
+Date: Sun Oct 29 21:31:23 2006 -0800
+Subject: [PATCH] Change _cairo_fixed_from_double to use the "magic number" technique
+
+See long thread here:
+http://lists.freedesktop.org/archives/cairo/2006-October/008285.html
+
+---
+
+ src/cairo-fixed.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 47 insertions(+), 1 deletions(-)
+
+d88acddcabe770e17664b34a2d5f74d3926e1642
+diff --git a/src/cairo-fixed.c b/src/cairo-fixed.c
+index 604c9e7..fe6c2dc 100644
+--- a/src/cairo-fixed.c
++++ b/src/cairo-fixed.c
+@@ -42,10 +42,56 @@ _cairo_fixed_from_int (int i)
+ return i << 16;
+ }
+
++/* This is the "magic number" approach to converting a double into fixed
++ * point as described here:
++ *
++ * http://www.stereopsis.com/sree/fpu2006.html (an overview)
++ * http://www.d6.com/users/checker/pdfs/gdmfp.pdf (in detail)
++ *
++ * The basic idea is to add a large enough number to the double that the
++ * literal floating point is moved up to the extent that it forces the
++ * double's value to be shifted down to the bottom of the mantissa (to make
++ * room for the large number being added in). Since the mantissa is, at a
++ * given moment in time, a fixed point integer itself, one can convert a
++ * float to various fixed point representations by moving around the point
++ * of a floating point number through arithmetic operations. This behavior
++ * is reliable on most modern platforms as it is mandated by the IEEE-754
++ * standard for floating point arithmetic.
++ *
++ * For our purposes, a "magic number" must be carefully selected that is
++ * both large enough to produce the desired point-shifting effect, and also
++ * has no lower bits in its representation that would interfere with our
++ * value at the bottom of the mantissa. The magic number is calculated as
++ * follows:
++ *
++ * (2 ^ (MANTISSA_SIZE - FRACTIONAL_SIZE)) * 1.5
++ *
++ * where in our case:
++ * - MANTISSA_SIZE for 64-bit doubles is 52
++ * - FRACTIONAL_SIZE for 16.16 fixed point is 16
++ *
++ * Although this approach provides a very large speedup of this function
++ * on a wide-array of systems, it does come with two caveats:
++ *
++ * 1) It uses banker's rounding as opposed to arithmetic rounding.
++ * 2) It doesn't function properly if the FPU is in single-precision
++ * mode.
++ */
++#define CAIRO_MAGIC_NUMBER_FIXED_16_16 (103079215104.0)
+ cairo_fixed_t
+ _cairo_fixed_from_double (double d)
+ {
+- return (cairo_fixed_t) floor (d * 65536 + 0.5);
++ union {
++ double d;
++ int32_t i[2];
++ } u;
++
++ u.d = d + CAIRO_MAGIC_NUMBER_FIXED_16_16;
++#ifdef FLOAT_WORDS_BIGENDIAN
++ return u.i[1];
++#else
++ return u.i[0];
++#endif
+ }
+
+ cairo_fixed_t
+--
+1.2.6
+
diff --git a/recipes/cairo/cairo-1.2.4/0003-Add-new-perf-test-pattern_create_radial.diff b/recipes/cairo/cairo-1.2.4/0003-Add-new-perf-test-pattern_create_radial.diff
new file mode 100644
index 0000000000..c2b47deb7f
--- /dev/null
+++ b/recipes/cairo/cairo-1.2.4/0003-Add-new-perf-test-pattern_create_radial.diff
@@ -0,0 +1,164 @@
+From nobody Mon Sep 17 00:00:00 2001
+From: Dan Amelang <dan@amelang.net>
+Date: Tue Oct 31 23:47:35 2006 -0800
+Subject: [PATCH] Add new perf test "pattern_create_radial"
+
+This test is really just for hammering the double to fixed-point conversion
+(in _cairo_fixed_from_double) that happens as doubles from API calls gets
+translated into internal cairo fixed-point numbers.
+
+Because it's not generally useful, I don't recommend that it become part of
+the main cairo performance test. But hey, it might come in handy for someone
+else.
+
+---
+
+ perf/Makefile.am | 1
+ perf/cairo-perf.c | 1
+ perf/cairo-perf.h | 1
+ perf/pattern_create_radial.c | 98 ++++++++++++++++++++++++++++++++++++++++++
+ 4 files changed, 101 insertions(+), 0 deletions(-)
+ create mode 100644 perf/pattern_create_radial.c
+
+977383b86c68d0523c899efcba3cf8d36e94d2a7
+diff --git a/perf/Makefile.am b/perf/Makefile.am
+index 419a998..e1cfdc7 100644
+--- a/perf/Makefile.am
++++ b/perf/Makefile.am
+@@ -21,6 +21,7 @@ cairo_perf_SOURCES = \
+ stroke.c \
+ subimage_copy.c \
+ tessellate.c \
++ pattern_create_radial.c \
+ text.c
+
+ if CAIRO_HAS_WIN32_SURFACE
+diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
+index d9734c4..0707433 100644
+--- a/perf/cairo-perf.c
++++ b/perf/cairo-perf.c
+@@ -256,5 +256,6 @@ cairo_perf_case_t perf_cases[] = {
+ { text, 64, 256},
+ { tessellate, 100, 100},
+ { subimage_copy, 16, 512},
++ { pattern_create_radial, 16, 16},
+ { NULL }
+ };
+diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
+index 560ba64..faacff9 100644
+--- a/perf/cairo-perf.h
++++ b/perf/cairo-perf.h
+@@ -88,5 +88,6 @@ CAIRO_PERF_DECL (stroke);
+ CAIRO_PERF_DECL (subimage_copy);
+ CAIRO_PERF_DECL (tessellate);
+ CAIRO_PERF_DECL (text);
++CAIRO_PERF_DECL (pattern_create_radial);
+
+ #endif
+diff --git a/perf/pattern_create_radial.c b/perf/pattern_create_radial.c
+new file mode 100644
+index 0000000..d793b7d
+--- /dev/null
++++ b/perf/pattern_create_radial.c
+@@ -0,0 +1,98 @@
++/*
++ * Copyright © 2006 Dan Amelang
++ *
++ * Permission to use, copy, modify, distribute, and sell this software
++ * and its documentation for any purpose is hereby granted without
++ * fee, provided that the above copyright notice appear in all copies
++ * and that both that copyright notice and this permission notice
++ * appear in supporting documentation, and that the name of
++ * the authors not be used in advertising or publicity pertaining to
++ * distribution of the software without specific, written prior
++ * permission. The authors make no representations about the
++ * suitability of this software for any purpose. It is provided "as
++ * is" without express or implied warranty.
++ *
++ * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
++ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
++ * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
++ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
++ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
++ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
++ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
++ *
++ * Authors: Dan Amelang <dan@amelang.net>
++ *
++ * This test was originally created to test _cairo_fixed_from_double.
++ * cairo_pattern_create_radial was selected as the entry point into
++ * cairo as it makes several calls to _cairo_fixed_from_double and
++ * presents a somewhat realistic use-case (although the RADIALS_COUNT
++ * isn't very realistic).
++ */
++#include <time.h>
++#include "cairo-perf.h"
++
++#define RADIALS_COUNT (100000)
++
++static struct
++{
++ double cx0;
++ double cy0;
++ double radius0;
++ double cx1;
++ double cy1;
++ double radius1;
++} radials[RADIALS_COUNT];
++
++static double
++generate_double_in_range (double min, double max)
++{
++ double d;
++
++ d = rand () / (double) RAND_MAX;
++ d *= max - min;
++ d += min;
++
++ return d;
++}
++
++static cairo_perf_ticks_t
++do_pattern_create_radial (cairo_t *cr, int width, int height)
++{
++ int i;
++ cairo_pattern_t *pattern;
++
++ cairo_perf_timer_start ();
++
++ for (i = 0; i < RADIALS_COUNT; i++)
++ {
++ pattern = cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0,
++ radials[i].radius0,
++ radials[i].cx1, radials[i].cy1,
++ radials[i].radius1);
++ cairo_pattern_destroy (pattern);
++ }
++
++ cairo_perf_timer_stop ();
++
++ return cairo_perf_timer_elapsed ();
++}
++
++void
++pattern_create_radial (cairo_perf_t *perf, cairo_t *cr, int width, int height)
++{
++ int i;
++
++ srand (time (0));
++ for (i = 0; i < RADIALS_COUNT; i++)
++ {
++ radials[i].cx0 = generate_double_in_range (-50000.0, 50000.0);
++ radials[i].cy0 = generate_double_in_range (-50000.0, 50000.0);
++ radials[i].radius0 = generate_double_in_range (0.0, 1000.0);
++ radials[i].cx1 = generate_double_in_range (-50000.0, 50000.0);
++ radials[i].cy1 = generate_double_in_range (-50000.0, 50000.0);
++ radials[i].radius1 = generate_double_in_range (0.0, 1000.0);
++ }
++
++ cairo_perf_run (perf, "pattern_create_radial",
++ do_pattern_create_radial);
++}
+--
+1.2.6
+
diff --git a/recipes/cairo/cairo-1.3.4/configure.in_requires_pkg-config-0.15.diff b/recipes/cairo/cairo-1.3.4/configure.in_requires_pkg-config-0.15.diff
new file mode 100644
index 0000000000..2bd70a532c
--- /dev/null
+++ b/recipes/cairo/cairo-1.3.4/configure.in_requires_pkg-config-0.15.diff
@@ -0,0 +1,13 @@
+Index: cairo-1.3.2-r0/cairo-1.3.2/configure.in
+===================================================================
+--- cairo-1.3.2-r0.orig/cairo-1.3.2/configure.in 2006-11-15 22:31:59.000000000 +0100
++++ cairo-1.3.2-r0/cairo-1.3.2/configure.in 2006-11-16 23:15:07.000000000 +0100
+@@ -90,7 +90,7 @@
+
+ dnl ===========================================================================
+
+-PKGCONFIG_REQUIRED=0.19
++PKGCONFIG_REQUIRED=0.15
+ PKG_PROG_PKG_CONFIG($PKGCONFIG_REQUIRED)
+ if test "x$PKG_CONFIG" = x; then
+ AC_MSG_ERROR([pkg-config >= $PKGCONFIG_REQUIRED required but not found (http://pkgconfig.freedesktop.org/)])
diff --git a/recipes/cairo/cairo-1.4.10/stats.patch b/recipes/cairo/cairo-1.4.10/stats.patch
new file mode 100644
index 0000000000..63df25c942
--- /dev/null
+++ b/recipes/cairo/cairo-1.4.10/stats.patch
@@ -0,0 +1,33 @@
+See cairo mailing list 15-10-2007 patch by Soeren Sandmann.
+Fixes unreliable results for cairo-perf.
+
+diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c
+index 360f2dd..a8d7abc 100644
+--- a/perf/cairo-perf.c
++++ b/perf/cairo-perf.c
+@@ -166,22 +166,11 @@ cairo_perf_run (cairo_perf_t *perf,
+ cairo_perf_ticks_per_second () / 1000.0);
+ printf (" %lld", times[i]);
+ } else {
+- if (i > 0) {
+- _cairo_stats_compute (&stats, times, i+1);
+-
+- if (stats.std_dev <= CAIRO_PERF_LOW_STD_DEV &&
+- ! perf->exact_iterations)
+- {
+- low_std_dev_count++;
+- if (low_std_dev_count >= CAIRO_PERF_STABLE_STD_DEV_COUNT)
+- break;
+- } else {
+- low_std_dev_count = 0;
+- }
+- }
+ }
+ }
+
++ _cairo_stats_compute (&stats, times, i+1);
++
+ if (perf->raw) {
+ printf ("\n");
+ } else {
+diff --git a/perf/cairo-stats.c b/perf/cairo-stats.c
diff --git a/recipes/cairo/cairo-1.4.14/0001-Fix-for-a-memory-leak-in-pixman.patch b/recipes/cairo/cairo-1.4.14/0001-Fix-for-a-memory-leak-in-pixman.patch
new file mode 100644
index 0000000000..686ab7ceb0
--- /dev/null
+++ b/recipes/cairo/cairo-1.4.14/0001-Fix-for-a-memory-leak-in-pixman.patch
@@ -0,0 +1,32 @@
+From 7647f29a2a3b69592e38f50890a96d8deeaa2dbb Mon Sep 17 00:00:00 2001
+From: Jan Slupski <jslupski@juljas.net>
+Date: Fri, 15 Feb 2008 00:55:30 +0100
+Subject: [PATCH] Fix for a memory leak in pixman.
+
+Port of a 1.6 fix for a memory leak in pixman_region_init_rects/pixman_rect_alloc
+when the count of boxes is 0.
+---
+ pixman/src/pixregion.c | 9 +++++++++
+ 1 files changed, 9 insertions(+), 0 deletions(-)
+
+diff --git a/pixman/src/pixregion.c b/pixman/src/pixregion.c
+index 1ed3ad7..d6caf6c 100644
+--- a/pixman/src/pixregion.c
++++ b/pixman/src/pixregion.c
+@@ -355,6 +355,15 @@ pixman_region_init_rects(pixman_region16_t *region, pixman_box16_t *boxes, int c
+ }
+
+ pixman_region_init(region);
++
++ /* if it's 0, don't call pixman_rect_alloc -- 0 rectangles is
++ * a special case, and causing pixman_rect_alloc would cause
++ * us to leak memory (because the 0-rect case should be the
++ * static pixman_region_emptyData data).
++ */
++ if (count == 0)
++ return PIXMAN_REGION_STATUS_SUCCESS;
++
+ if (!pixman_rect_alloc(region, count))
+ return PIXMAN_REGION_STATUS_FAILURE;
+
+
diff --git a/recipes/cairo/cairo-1.4.4/cairo-workqueue.patch b/recipes/cairo/cairo-1.4.4/cairo-workqueue.patch
new file mode 100644
index 0000000000..4522e99e68
--- /dev/null
+++ b/recipes/cairo/cairo-1.4.4/cairo-workqueue.patch
@@ -0,0 +1,2148 @@
+From: Chris Wilson <chris@chris-wilson.co.uk>
+Date: Wed, 18 Apr 2007 17:34:44 +0000 (+0100)
+Subject: Cache freed GCs
+X-Git-Url: http://gitweb.freedesktop.org/?p=users/ickle/cairo;a=commitdiff;h=3126c3948691cf7a6c0fc0f9cc6a7eca43c3553b
+
+Cache freed GCs
+
+Maintain a cache of freed GCs, one for each used depth.
+---
+
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -46,7 +46,11 @@ endif
+
+ if CAIRO_HAS_XLIB_SURFACE
+ libcairo_xlib_headers = cairo-xlib.h cairo-xlib-xrender.h
+-libcairo_xlib_sources = cairo-xlib-surface.c cairo-xlib-screen.c cairo-xlib-private.h cairo-xlib-test.h
++libcairo_xlib_sources = cairo-xlib-surface.c \
++ cairo-xlib-display.c \
++ cairo-xlib-screen.c \
++ cairo-xlib-private.h \
++ cairo-xlib-test.h
+ backend_pkgconfigs += cairo-xlib.pc
+ endif
+
+--- a/src/cairo-clip.c
++++ b/src/cairo-clip.c
+@@ -404,7 +404,8 @@ _cairo_clip_intersect_mask (cairo_clip_t
+ CAIRO_CONTENT_ALPHA,
+ surface_rect.width,
+ surface_rect.height,
+- CAIRO_COLOR_WHITE);
++ CAIRO_COLOR_WHITE,
++ NULL);
+ if (surface->status)
+ return CAIRO_STATUS_NO_MEMORY;
+
+--- a/src/cairo-debug.c
++++ b/src/cairo-debug.c
+@@ -59,10 +59,6 @@
+ void
+ cairo_debug_reset_static_data (void)
+ {
+-#if CAIRO_HAS_XLIB_SURFACE
+- _cairo_xlib_screen_reset_static_data ();
+-#endif
+-
+ _cairo_font_reset_static_data ();
+
+ #if CAIRO_HAS_FT_FONT
+--- a/src/cairo-directfb-surface.c
++++ b/src/cairo-directfb-surface.c
+@@ -1511,6 +1511,16 @@ _cairo_directfb_surface_show_glyphs ( vo
+ #endif /* DFB_SHOW_GLYPHS */
+
+
++static cairo_bool_t
++_cairo_directfb_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_directfb_surface_t *a = (cairo_directfb_surface_t *) surface_a;
++ cairo_directfb_surface_t *b = (cairo_directfb_surface_t *) surface_b;
++
++ return a->dfb == b->dfb;
++}
++
+ static cairo_surface_backend_t cairo_directfb_surface_backend = {
+ CAIRO_SURFACE_TYPE_DIRECTFB, /*type*/
+ _cairo_directfb_surface_create_similar,/*create_similar*/
+@@ -1560,7 +1570,8 @@ static cairo_surface_backend_t cairo_dir
+ #else
+ NULL, /* show_glyphs */
+ #endif
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_directfb_is_compatible
+ };
+
+
+--- a/src/cairo-glitz-surface.c
++++ b/src/cairo-glitz-surface.c
+@@ -1002,7 +1002,8 @@ _cairo_glitz_surface_fill_rectangles (vo
+ _cairo_surface_create_similar_solid (&dst->base,
+ CAIRO_CONTENT_COLOR_ALPHA,
+ 1, 1,
+- (cairo_color_t *) color);
++ (cairo_color_t *) color,
++ NULL);
+ if (src->base.status)
+ return CAIRO_STATUS_NO_MEMORY;
+
+@@ -2171,6 +2172,19 @@ _cairo_glitz_surface_flush (void *abstra
+ return CAIRO_STATUS_SUCCESS;
+ }
+
++static cairo_bool_t
++_cairo_glitz_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_glitz_surface_t *a = (cairo_glitz_surface_t *) surface_a;
++ cairo_glitz_surface_t *b = (cairo_glitz_surface_t *) surface_b;
++
++ glitz_drawable_t *drawable_a = glitz_surface_get_drawable (a->surface);
++ glitz_drawable_t *drawable_b = glitz_surface_get_drawable (b->surface);
++
++ return drawable_a == drawable_b;
++}
++
+ static const cairo_surface_backend_t cairo_glitz_surface_backend = {
+ CAIRO_SURFACE_TYPE_GLITZ,
+ _cairo_glitz_surface_create_similar,
+@@ -2193,7 +2207,16 @@ static const cairo_surface_backend_t cai
+ _cairo_glitz_surface_flush,
+ NULL, /* mark_dirty_rectangle */
+ _cairo_glitz_surface_scaled_font_fini,
+- _cairo_glitz_surface_scaled_glyph_fini
++ _cairo_glitz_surface_scaled_glyph_fini,
++
++ NULL, /* paint */
++ NULL, /* mask */
++ NULL, /* stroke */
++ NULL, /* fill */
++ NULL, /* show_glyphs */
++
++ NULL, /* snapshot */
++ _cairo_glitz_surface_is_compatible
+ };
+
+ static const cairo_surface_backend_t *
+--- a/src/cairo-mutex-list-private.h
++++ b/src/cairo-mutex-list-private.h
+@@ -34,7 +34,8 @@
+ #ifndef CAIRO_MUTEX_LIST_PRIVATE_H
+ #define CAIRO_MUTEX_LIST_PRIVATE_H
+
+-CAIRO_MUTEX_DECLARE (_cairo_pattern_solid_cache_lock);
++CAIRO_MUTEX_DECLARE (_cairo_pattern_solid_pattern_cache_lock);
++CAIRO_MUTEX_DECLARE (_cairo_pattern_solid_surface_cache_lock);
+
+ CAIRO_MUTEX_DECLARE (_cairo_font_face_mutex);
+ CAIRO_MUTEX_DECLARE (_cairo_scaled_font_map_mutex);
+@@ -44,7 +45,7 @@ CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_
+ #endif
+
+ #if CAIRO_HAS_XLIB_SURFACE
+-CAIRO_MUTEX_DECLARE (_cairo_xlib_screen_mutex);
++CAIRO_MUTEX_DECLARE (_cairo_xlib_display_mutex);
+ #endif
+
+ #endif
+--- a/src/cairo-pattern.c
++++ b/src/cairo-pattern.c
+@@ -282,7 +282,7 @@ _cairo_pattern_create_solid (const cairo
+ {
+ cairo_solid_pattern_t *pattern = NULL;
+
+- CAIRO_MUTEX_LOCK (_cairo_pattern_solid_cache_lock);
++ CAIRO_MUTEX_LOCK (_cairo_pattern_solid_pattern_cache_lock);
+
+ if (solid_pattern_cache.size) {
+ int i = --solid_pattern_cache.size %
+@@ -291,7 +291,7 @@ _cairo_pattern_create_solid (const cairo
+ solid_pattern_cache.patterns[i] = NULL;
+ }
+
+- CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_cache_lock);
++ CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_pattern_cache_lock);
+
+ if (pattern == NULL) {
+ /* None cached, need to create a new pattern. */
+@@ -306,12 +306,12 @@ _cairo_pattern_create_solid (const cairo
+ return &pattern->base;
+ }
+
+-void
+-_cairo_pattern_reset_static_data (void)
++static void
++_cairo_pattern_reset_solid_pattern_cache (void)
+ {
+ int i;
+
+- CAIRO_MUTEX_LOCK (_cairo_pattern_solid_cache_lock);
++ CAIRO_MUTEX_LOCK (_cairo_pattern_solid_pattern_cache_lock);
+
+ for (i = 0; i < MIN (ARRAY_LENGTH (solid_pattern_cache.patterns), solid_pattern_cache.size); i++) {
+ free (solid_pattern_cache.patterns[i]);
+@@ -319,7 +319,7 @@ _cairo_pattern_reset_static_data (void)
+ }
+ solid_pattern_cache.size = 0;
+
+- CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_cache_lock);
++ CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_pattern_cache_lock);
+ }
+
+ static const cairo_pattern_t *
+@@ -630,7 +630,7 @@ cairo_pattern_destroy (cairo_pattern_t *
+ if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) {
+ int i;
+
+- CAIRO_MUTEX_LOCK (_cairo_pattern_solid_cache_lock);
++ CAIRO_MUTEX_LOCK (_cairo_pattern_solid_pattern_cache_lock);
+
+ i = solid_pattern_cache.size++ %
+ ARRAY_LENGTH (solid_pattern_cache.patterns);
+@@ -640,7 +640,7 @@ cairo_pattern_destroy (cairo_pattern_t *
+
+ solid_pattern_cache.patterns[i] = (cairo_solid_pattern_t *) pattern;
+
+- CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_cache_lock);
++ CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_pattern_cache_lock);
+ } else {
+ free (pattern);
+ }
+@@ -1235,6 +1235,17 @@ _cairo_pattern_acquire_surface_for_gradi
+ return status;
+ }
+
++/* We maintain a small cache here, because we don't want to constantly
++ * recreate surfaces for simple solid colors. */
++#define MAX_SURFACE_CACHE_SIZE 16
++static struct {
++ struct {
++ cairo_color_t color;
++ cairo_surface_t *surface;
++ } cache[MAX_SURFACE_CACHE_SIZE];
++ int size;
++} solid_surface_cache;
++
+ static cairo_int_status_t
+ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern,
+ cairo_surface_t *dst,
+@@ -1245,12 +1256,54 @@ _cairo_pattern_acquire_surface_for_solid
+ cairo_surface_t **out,
+ cairo_surface_attributes_t *attribs)
+ {
+- *out = _cairo_surface_create_similar_solid (dst,
+- CAIRO_CONTENT_COLOR_ALPHA,
+- 1, 1,
+- &pattern->color);
+- if ((*out)->status)
+- return CAIRO_STATUS_NO_MEMORY;
++ static int i;
++
++ cairo_surface_t *surface;
++ cairo_status_t status;
++
++ CAIRO_MUTEX_LOCK (_cairo_pattern_solid_surface_cache_lock);
++
++ /* Check cache first */
++ if (i < solid_surface_cache.size &&
++ _cairo_color_equal (&solid_surface_cache.cache[i].color,
++ &pattern->color) &&
++ _cairo_surface_is_compatible (solid_surface_cache.cache[i].surface, dst))
++ goto DONE;
++
++ for (i = 0 ; i < solid_surface_cache.size; i++) {
++ if (_cairo_color_equal (&solid_surface_cache.cache[i].color,
++ &pattern->color) &&
++ _cairo_surface_is_compatible (solid_surface_cache.cache[i].surface, dst))
++ goto DONE;
++ }
++
++ /* Not cached, need to create new */
++ surface = _cairo_surface_create_similar_solid (dst,
++ CAIRO_CONTENT_COLOR_ALPHA,
++ 1, 1,
++ &pattern->color,
++ pattern);
++ assert (_cairo_surface_is_compatible (surface, dst));
++ if (surface->status) {
++ status = surface->status;
++ goto UNLOCK;
++ }
++
++ /* Cache new */
++ if (solid_surface_cache.size < MAX_SURFACE_CACHE_SIZE) {
++ solid_surface_cache.size++;
++ } else {
++ i = rand () % MAX_SURFACE_CACHE_SIZE;
++
++ /* Evict old */
++ cairo_surface_destroy (solid_surface_cache.cache[i].surface);
++ }
++
++ solid_surface_cache.cache[i].color = pattern->color;
++ solid_surface_cache.cache[i].surface = surface;
++
++DONE:
++ *out = cairo_surface_reference (solid_surface_cache.cache[i].surface);
+
+ attribs->x_offset = attribs->y_offset = 0;
+ cairo_matrix_init_identity (&attribs->matrix);
+@@ -1258,7 +1311,26 @@ _cairo_pattern_acquire_surface_for_solid
+ attribs->filter = CAIRO_FILTER_NEAREST;
+ attribs->acquired = FALSE;
+
+- return CAIRO_STATUS_SUCCESS;
++ status = CAIRO_STATUS_SUCCESS;
++
++UNLOCK:
++ CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_surface_cache_lock);
++
++ return status;
++}
++
++static void
++_cairo_pattern_reset_solid_surface_cache (void)
++{
++ int i;
++
++ CAIRO_MUTEX_LOCK (_cairo_pattern_solid_surface_cache_lock);
++
++ for (i = 0; i < solid_surface_cache.size; i++)
++ cairo_surface_destroy (solid_surface_cache.cache[i].surface);
++ solid_surface_cache.size = 0;
++
++ CAIRO_MUTEX_UNLOCK (_cairo_pattern_solid_surface_cache_lock);
+ }
+
+ /**
+@@ -2049,3 +2121,10 @@ cairo_pattern_get_radial_circles (cairo_
+
+ return CAIRO_STATUS_SUCCESS;
+ }
++
++void
++_cairo_pattern_reset_static_data (void)
++{
++ _cairo_pattern_reset_solid_pattern_cache ();
++ _cairo_pattern_reset_solid_surface_cache ();
++}
+--- a/src/cairo-surface.c
++++ b/src/cairo-surface.c
+@@ -288,7 +288,8 @@ cairo_surface_create_similar (cairo_surf
+
+ return _cairo_surface_create_similar_solid (other, content,
+ width, height,
+- CAIRO_COLOR_TRANSPARENT);
++ CAIRO_COLOR_TRANSPARENT,
++ NULL);
+ }
+ slim_hidden_def (cairo_surface_create_similar);
+
+@@ -297,7 +298,8 @@ _cairo_surface_create_similar_solid (cai
+ cairo_content_t content,
+ int width,
+ int height,
+- const cairo_color_t *color)
++ const cairo_color_t *color,
++ cairo_pattern_t *pattern)
+ {
+ cairo_status_t status;
+ cairo_surface_t *surface;
+@@ -310,19 +312,23 @@ _cairo_surface_create_similar_solid (cai
+ return (cairo_surface_t*) &_cairo_surface_nil;
+ }
+
+- source = _cairo_pattern_create_solid (color);
+- if (source->status) {
+- cairo_surface_destroy (surface);
+- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+- return (cairo_surface_t*) &_cairo_surface_nil;
+- }
++ if (pattern == NULL) {
++ source = _cairo_pattern_create_solid (color);
++ if (source->status) {
++ cairo_surface_destroy (surface);
++ _cairo_error (CAIRO_STATUS_NO_MEMORY);
++ return (cairo_surface_t*) &_cairo_surface_nil;
++ }
++ } else
++ source = pattern;
+
+ status = _cairo_surface_paint (surface,
+ color == CAIRO_COLOR_TRANSPARENT ?
+ CAIRO_OPERATOR_CLEAR :
+ CAIRO_OPERATOR_SOURCE, source);
+
+- cairo_pattern_destroy (source);
++ if (source != pattern)
++ cairo_pattern_destroy (source);
+
+ if (status) {
+ cairo_surface_destroy (surface);
+@@ -1056,6 +1062,32 @@ _cairo_surface_snapshot (cairo_surface_t
+ return _cairo_surface_fallback_snapshot (surface);
+ }
+
++/**
++ * _cairo_surface_is_compatible
++ * @surface_a: a #cairo_surface_t
++ * @surface_b: a #cairo_surface_t
++ *
++ * Find out whether the given surfaces share the same backend,
++ * and if so, whether they can be considered compatible.
++ *
++ * The definition of "compatible" depends on the backend. In the
++ * xlib case, it means the surface share the same display.
++ *
++ * Return value: TRUE if the surfaces are compatible.
++ **/
++cairo_bool_t
++_cairo_surface_is_compatible (cairo_surface_t *surface_a,
++ cairo_surface_t *surface_b)
++{
++ if (surface_a->backend != surface_b->backend)
++ return FALSE;
++
++ if (surface_a->backend->is_compatible != NULL)
++ return surface_a->backend->is_compatible (surface_a, surface_b);
++
++ return TRUE;
++}
++
+ cairo_status_t
+ _cairo_surface_composite (cairo_operator_t op,
+ cairo_pattern_t *src,
+--- a/src/cairo-win32-surface.c
++++ b/src/cairo-win32-surface.c
+@@ -1854,6 +1854,16 @@ cairo_win32_surface_get_image (cairo_sur
+ return ((cairo_win32_surface_t*)surface)->image;
+ }
+
++static cairo_bool_t
++_cairo_win32_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_win32_surface_t *a = (cairo_win32_surface_t *) surface_a;
++ cairo_win32_surface_t *b = (cairo_win32_surface_t *) surface_b;
++
++ return a->dc == b->dc;
++}
++
+ static const cairo_surface_backend_t cairo_win32_surface_backend = {
+ CAIRO_SURFACE_TYPE_WIN32,
+ _cairo_win32_surface_create_similar,
+@@ -1884,7 +1894,8 @@ static const cairo_surface_backend_t cai
+ NULL, /* fill */
+ _cairo_win32_surface_show_glyphs,
+
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_win32_surface_is_compatible
+ };
+
+ /* Notes:
+--- a/src/cairo-xcb-surface.c
++++ b/src/cairo-xcb-surface.c
+@@ -1577,6 +1577,16 @@ _cairo_xcb_surface_show_glyphs (void
+ int num_glyphs,
+ cairo_scaled_font_t *scaled_font);
+
++static cairo_bool_t
++_cairo_xcb_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_xcb_surface_t *a = (cairo_xcb_surface_t *) surface_a;
++ cairo_xcb_surface_t *b = (cairo_xcb_surface_t *) surface_b;
++
++ return _cairo_xcb_surface_same_screen (dst, src);
++}
++
+ /* XXX: move this to the bottom of the file, XCB and Xlib */
+
+ static const cairo_surface_backend_t cairo_xcb_surface_backend = {
+@@ -1608,7 +1618,8 @@ static const cairo_surface_backend_t cai
+ NULL, /* stroke */
+ NULL, /* fill */
+ _cairo_xcb_surface_show_glyphs,
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_xcb_surface_is_compatible
+ };
+
+ /**
+--- /dev/null
++++ b/src/cairo-xlib-display.c
+@@ -0,0 +1,490 @@
++/* Cairo - a vector graphics library with display and print output
++ *
++ * Copyright © 2007 Chris Wilson
++ *
++ * This library is free software; you can redistribute it and/or
++ * modify it either under the terms of the GNU Lesser General Public
++ * License version 2.1 as published by the Free Software Foundation
++ * (the "LGPL") or, at your option, under the terms of the Mozilla
++ * Public License Version 1.1 (the "MPL"). If you do not alter this
++ * notice, a recipient may use your version of this file under either
++ * the MPL or the LGPL.
++ *
++ * You should have received a copy of the LGPL along with this library
++ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
++ * You should have received a copy of the MPL along with this library
++ * in the file COPYING-MPL-1.1
++ *
++ * The contents of this file are subject to the Mozilla Public License
++ * Version 1.1 (the "License"); you may not use this file except in
++ * compliance with the License. You may obtain a copy of the License at
++ * http://www.mozilla.org/MPL/
++ *
++ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
++ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
++ * the specific language governing rights and limitations.
++ *
++ * The Original Code is the cairo graphics library.
++ *
++ * The Initial Developer of the Original Code is Chris Wilson.
++ *
++ */
++
++#include "cairoint.h"
++
++#include "cairo-xlib-private.h"
++
++#include <fontconfig/fontconfig.h>
++
++#include <X11/Xlibint.h> /* For XESetCloseDisplay */
++#include <X11/extensions/Xrender.h>
++
++typedef int (*cairo_xlib_error_func_t) (Display *display,
++ XErrorEvent *event);
++
++struct _cairo_xlib_job {
++ cairo_xlib_job_t *next;
++ enum {
++ RESOURCE,
++ WORK
++ } type;
++ union {
++ struct {
++ cairo_xlib_notify_resource_func notify;
++ XID xid;
++ } resource;
++ struct {
++ cairo_xlib_notify_func notify;
++ void *data;
++ void (*destroy) (void *);
++ } work;
++ } func;
++};
++
++static cairo_xlib_display_t *_cairo_xlib_display_list = NULL;
++
++static void
++_cairo_xlib_call_close_display_hooks (cairo_xlib_display_t *info)
++{
++ cairo_xlib_screen_info_t *screen;
++ cairo_xlib_hook_t *hooks;
++
++ /* call all registered shutdown routines */
++ CAIRO_MUTEX_LOCK (info->mutex);
++
++ for (screen = info->screens; screen != NULL; screen = screen->next)
++ _cairo_xlib_screen_info_close_display (screen);
++
++ hooks = info->close_display_hooks;
++ while (hooks != NULL) {
++ info->close_display_hooks = NULL;
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++
++ do {
++ cairo_xlib_hook_t *hook = hooks;
++ hooks = hook->next;
++
++ hook->func (info->display, hook->data);
++
++ free (hook);
++ } while (hooks != NULL);
++
++ CAIRO_MUTEX_LOCK (info->mutex);
++ hooks = info->close_display_hooks;
++ }
++ info->closed = TRUE;
++
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++}
++
++cairo_xlib_display_t *
++_cairo_xlib_display_reference (cairo_xlib_display_t *info)
++{
++ if (info == NULL)
++ return NULL;
++
++ /* use our mutex until we get a real atomic inc */
++ CAIRO_MUTEX_LOCK (info->mutex);
++
++ assert (info->ref_count > 0);
++ info->ref_count++;
++
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++
++ return info;
++}
++
++void
++_cairo_xlib_display_destroy (cairo_xlib_display_t *info)
++{
++ if (info == NULL)
++ return;
++
++ CAIRO_MUTEX_LOCK (info->mutex);
++ assert (info->ref_count > 0);
++ if (--info->ref_count == 0) {
++ assert (info->closed == TRUE);
++ assert (info->screens == NULL);
++
++ /* destroy all outstanding notifies */
++ while (info->workqueue != NULL) {
++ cairo_xlib_job_t *job = info->workqueue;
++ info->workqueue = job->next;
++
++ if (job->type == WORK && job->func.work.destroy != NULL)
++ job->func.work.destroy (job->func.work.data);
++
++ _cairo_freelist_free (&info->wq_freelist, job);
++ }
++ _cairo_freelist_fini (&info->wq_freelist);
++
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++
++ free (info);
++ } else
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++}
++
++static int
++_noop_error_handler (Display *display,
++ XErrorEvent *event)
++{
++ return False; /* return value is ignored */
++}
++static int
++_cairo_xlib_close_display (Display *dpy, XExtCodes *codes)
++{
++ cairo_xlib_display_t *info, **prev, *next;
++
++ /*
++ * Unhook from the global list
++ */
++ CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex);
++ prev = &_cairo_xlib_display_list;
++ for (info = _cairo_xlib_display_list; info; info = next) {
++ next = info->next;
++ if (info->display == dpy) {
++ cairo_xlib_error_func_t old_handler;
++
++ /* drop the list mutex whilst triggering the hooks */
++ CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex);
++
++ /* protect the notifies from triggering XErrors */
++ old_handler = XSetErrorHandler (_noop_error_handler);
++
++ _cairo_xlib_display_notify (info);
++ _cairo_xlib_call_close_display_hooks (info);
++
++ /* catch any that arrived before marking the display as closed */
++ _cairo_xlib_display_notify (info);
++
++ XSync (dpy, False);
++ XSetErrorHandler (old_handler);
++
++ CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex);
++ _cairo_xlib_display_destroy (info);
++ *prev = next;
++ break;
++ } else
++ prev = &info->next;
++ }
++ CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex);
++
++ /* Return value in accordance with requirements of
++ * XESetCloseDisplay */
++ return 0;
++}
++
++cairo_xlib_display_t *
++_cairo_xlib_display_get (Display *dpy)
++{
++ cairo_xlib_display_t *info;
++ cairo_xlib_display_t **prev;
++ XExtCodes *codes;
++
++ /* There is an apparent deadlock between this mutex and the
++ * mutex for the display, but it's actually safe. For the
++ * app to call XCloseDisplay() while any other thread is
++ * inside this function would be an error in the logic
++ * app, and the CloseDisplay hook is the only other place we
++ * acquire this mutex.
++ */
++ CAIRO_MUTEX_LOCK (_cairo_xlib_display_mutex);
++
++ for (prev = &_cairo_xlib_display_list; (info = *prev); prev = &(*prev)->next)
++ {
++ if (info->display == dpy) {
++ /*
++ * MRU the list
++ */
++ if (prev != &_cairo_xlib_display_list) {
++ *prev = info->next;
++ info->next = _cairo_xlib_display_list;
++ _cairo_xlib_display_list = info;
++ }
++ break;
++ }
++ }
++
++ if (info != NULL) {
++ info = _cairo_xlib_display_reference (info);
++ goto UNLOCK;
++ }
++
++ info = malloc (sizeof (cairo_xlib_display_t));
++ if (info == NULL)
++ goto UNLOCK;
++
++ codes = XAddExtension (dpy);
++ if (codes == NULL) {
++ free (info);
++ info = NULL;
++ goto UNLOCK;
++ }
++
++ XESetCloseDisplay (dpy, codes->extension, _cairo_xlib_close_display);
++
++ _cairo_freelist_init (&info->wq_freelist, sizeof (cairo_xlib_job_t));
++ info->ref_count = 2; /* add one for the CloseDisplay */
++ CAIRO_MUTEX_INIT (&info->mutex);
++ info->display = dpy;
++ info->screens = NULL;
++ info->workqueue = NULL;
++ info->close_display_hooks = NULL;
++ info->closed = FALSE;
++
++ info->next = _cairo_xlib_display_list;
++ _cairo_xlib_display_list = info;
++
++UNLOCK:
++ CAIRO_MUTEX_UNLOCK (_cairo_xlib_display_mutex);
++ return info;
++}
++
++cairo_bool_t
++_cairo_xlib_add_close_display_hook (Display *dpy, void (*func) (Display *, void *), void *data, const void *key)
++{
++ cairo_xlib_display_t *info;
++ cairo_xlib_hook_t *hook;
++ cairo_bool_t ret = FALSE;
++
++ info = _cairo_xlib_display_get (dpy);
++ if (info == NULL)
++ return FALSE;
++
++ hook = malloc (sizeof (cairo_xlib_hook_t));
++ if (hook != NULL) {
++ hook->func = func;
++ hook->data = data;
++ hook->key = key;
++
++ CAIRO_MUTEX_LOCK (info->mutex);
++ if (info->closed == FALSE) {
++ hook->next = info->close_display_hooks;
++ info->close_display_hooks = hook;
++ ret = TRUE;
++ }
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++ }
++
++ _cairo_xlib_display_destroy (info);
++
++ return ret;
++}
++
++void
++_cairo_xlib_remove_close_display_hooks (Display *dpy, const void *key)
++{
++ cairo_xlib_display_t *info;
++ cairo_xlib_hook_t *hook, *next, **prev;
++
++ info = _cairo_xlib_display_get (dpy);
++ if (info == NULL)
++ return;
++
++ CAIRO_MUTEX_LOCK (info->mutex);
++ prev = &info->close_display_hooks;
++ for (hook = info->close_display_hooks; hook != NULL; hook = next) {
++ next = hook->next;
++ if (hook->key == key) {
++ *prev = hook->next;
++ free (hook);
++ } else
++ prev = &hook->next;
++ }
++ *prev = NULL;
++ CAIRO_MUTEX_UNLOCK (info->mutex);
++
++ _cairo_xlib_display_destroy (info);
++}
++
++void
++_cairo_xlib_display_cancel_resource (cairo_xlib_display_t *display,
++ XID xid)
++{
++ cairo_xlib_job_t *job, *next, **prev;
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ prev = &display->workqueue;
++ for (job = display->workqueue; job != NULL; job = next) {
++ next = job->next;
++ if (job->type == RESOURCE && job->func.resource.xid == xid) {
++ _cairo_freelist_free (&display->wq_freelist, job);
++
++ *prev = next;
++ break;
++ }
++ prev = &job->next;
++ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++}
++
++static cairo_xlib_job_t *
++_cairo_xlib_display_find_resource (cairo_xlib_display_t *display, XID xid)
++{
++ cairo_xlib_job_t *job;
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ for (job = display->workqueue; job != NULL; job = job->next) {
++ if (job->type == RESOURCE && job->func.resource.xid == xid)
++ break;
++ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++
++ return job;
++}
++
++cairo_status_t
++_cairo_xlib_display_queue_resource (cairo_xlib_display_t *display,
++ cairo_xlib_notify_resource_func notify,
++ XID xid)
++{
++ cairo_xlib_job_t *job;
++ cairo_status_t status = CAIRO_STATUS_SUCCESS;
++
++ assert (_cairo_xlib_display_find_resource (display, xid) == NULL);
++
++ job = _cairo_freelist_alloc (&display->wq_freelist);
++ if (job == NULL)
++ return CAIRO_STATUS_NO_MEMORY;
++
++ job->type = RESOURCE;
++ job->func.resource.xid = xid;
++ job->func.resource.notify = notify;
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ if (display->closed == FALSE) {
++ job->next = display->workqueue;
++ display->workqueue = job;
++ } else {
++ _cairo_freelist_free (&display->wq_freelist, job);
++ job = NULL;
++ status = CAIRO_STATUS_NO_MEMORY;
++ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++
++ return status;
++}
++
++void
++_cairo_xlib_display_cancel_work (cairo_xlib_display_t *display,
++ void *data)
++{
++ cairo_xlib_job_t *job, *next, **prev;
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ prev = &display->workqueue;
++ for (job = display->workqueue; job != NULL; job = next) {
++ next = job->next;
++ if (job->type == WORK && job->func.work.data == data) {
++ if (job->func.work.destroy != NULL)
++ job->func.work.destroy (job->func.work.data);
++ _cairo_freelist_free (&display->wq_freelist, job);
++
++ *prev = next;
++ break;
++ }
++ prev = &job->next;
++ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++}
++
++cairo_status_t
++_cairo_xlib_display_queue_work (cairo_xlib_display_t *display,
++ cairo_xlib_notify_func notify,
++ void *data,
++ void (*destroy) (void *))
++{
++ cairo_xlib_job_t *job;
++ cairo_status_t status = CAIRO_STATUS_SUCCESS;
++
++ job = _cairo_freelist_alloc (&display->wq_freelist);
++ if (job == NULL)
++ return CAIRO_STATUS_NO_MEMORY;
++
++ job->type = WORK;
++ job->func.work.data = data;
++ job->func.work.notify = notify;
++ job->func.work.destroy = destroy;
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ if (display->closed == FALSE) {
++ job->next = display->workqueue;
++ display->workqueue = job;
++ } else {
++ _cairo_freelist_free (&display->wq_freelist, job);
++ job = NULL;
++ status = CAIRO_STATUS_NO_MEMORY;
++ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++
++ return status;
++}
++
++void
++_cairo_xlib_display_notify (cairo_xlib_display_t *display)
++{
++ cairo_xlib_job_t *jobs, *job;
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ jobs = display->workqueue;
++ while (jobs != NULL) {
++ display->workqueue = NULL;
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++
++ /* reverse the list to obtain FIFO order */
++ job = NULL;
++ do {
++ cairo_xlib_job_t *next = jobs->next;
++ jobs->next = job;
++ job = jobs;
++ jobs = next;
++ } while (jobs != NULL);
++ jobs = job;
++
++ do {
++ job = jobs;
++ jobs = job->next;
++
++ switch (job->type){
++ case WORK:
++ job->func.work.notify (display->display, job->func.work.data);
++ if (job->func.work.destroy != NULL)
++ job->func.work.destroy (job->func.work.data);
++ break;
++
++ case RESOURCE:
++ job->func.resource.notify (display->display,
++ job->func.resource.xid);
++ break;
++ }
++
++ _cairo_freelist_free (&display->wq_freelist, job);
++ } while (jobs != NULL);
++
++ CAIRO_MUTEX_LOCK (display->mutex);
++ jobs = display->workqueue;
++ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++}
+--- a/src/cairo-xlib-private.h
++++ b/src/cairo-xlib-private.h
+@@ -35,30 +35,82 @@
+
+ #include "cairoint.h"
+ #include "cairo-xlib.h"
++#include "cairo-freelist-private.h"
+
++typedef struct _cairo_xlib_display cairo_xlib_display_t;
+ typedef struct _cairo_xlib_screen_info cairo_xlib_screen_info_t;
+ typedef struct _cairo_xlib_hook cairo_xlib_hook_t;
++typedef struct _cairo_xlib_job cairo_xlib_job_t;
++typedef void (*cairo_xlib_notify_func) (Display *, void *);
++typedef void (*cairo_xlib_notify_resource_func) (Display *, XID);
+
+ struct _cairo_xlib_hook {
+ cairo_xlib_hook_t *next;
+ void (*func) (Display *display, void *data);
+ void *data;
+- void *key;
++ const void *key;
++};
++
++struct _cairo_xlib_display {
++ cairo_xlib_display_t *next;
++ unsigned int ref_count;
++ cairo_mutex_t mutex;
++
++ Display *display;
++ cairo_xlib_screen_info_t *screens;
++
++ cairo_xlib_job_t *workqueue;
++ cairo_freelist_t wq_freelist;
++
++ cairo_xlib_hook_t *close_display_hooks;
++ unsigned int closed :1;
+ };
+
+ struct _cairo_xlib_screen_info {
+ cairo_xlib_screen_info_t *next;
+ unsigned int ref_count;
+
+- Display *display;
++ cairo_xlib_display_t *display;
+ Screen *screen;
+ cairo_bool_t has_render;
+
+ cairo_font_options_t font_options;
+
+- cairo_xlib_hook_t *close_display_hooks;
++ GC gc[6];
+ };
+
++cairo_private cairo_xlib_display_t *
++_cairo_xlib_display_get (Display *display);
++
++cairo_private cairo_xlib_display_t *
++_cairo_xlib_display_reference (cairo_xlib_display_t *info);
++cairo_private void
++_cairo_xlib_display_destroy (cairo_xlib_display_t *info);
++
++cairo_private cairo_bool_t
++_cairo_xlib_add_close_display_hook (Display *display, void (*func) (Display *, void *), void *data, const void *key);
++cairo_private void
++_cairo_xlib_remove_close_display_hooks (Display *display, const void *key);
++
++cairo_private cairo_status_t
++_cairo_xlib_display_queue_work (cairo_xlib_display_t *display,
++ cairo_xlib_notify_func notify,
++ void *data,
++ void (*destroy)(void *));
++cairo_private cairo_status_t
++_cairo_xlib_display_queue_resource (cairo_xlib_display_t *display,
++ cairo_xlib_notify_resource_func notify,
++ XID resource);
++cairo_private void
++_cairo_xlib_display_cancel_work (cairo_xlib_display_t *display,
++ void *data);
++cairo_private void
++_cairo_xlib_display_cancel_resource (cairo_xlib_display_t *display,
++ XID resource);
++
++cairo_private void
++_cairo_xlib_display_notify (cairo_xlib_display_t *display);
++
+ cairo_private cairo_xlib_screen_info_t *
+ _cairo_xlib_screen_info_get (Display *display, Screen *screen);
+
+@@ -67,10 +119,14 @@ _cairo_xlib_screen_info_reference (cairo
+ cairo_private void
+ _cairo_xlib_screen_info_destroy (cairo_xlib_screen_info_t *info);
+
+-cairo_private cairo_bool_t
+-_cairo_xlib_add_close_display_hook (Display *display, void (*func) (Display *, void *), void *data, void *key);
+ cairo_private void
+-_cairo_xlib_remove_close_display_hook (Display *display, void *key);
++_cairo_xlib_screen_info_close_display (cairo_xlib_screen_info_t *info);
++
++
++cairo_private GC
++_cairo_xlib_screen_get_gc (cairo_xlib_screen_info_t *info, int depth);
++cairo_private void
++_cairo_xlib_screen_put_gc (cairo_xlib_screen_info_t *info, int depth, GC gc);
+
+ #if CAIRO_HAS_XLIB_XRENDER_SURFACE
+
+--- a/src/cairo-xlib-screen.c
++++ b/src/cairo-xlib-screen.c
+@@ -58,7 +58,6 @@
+
+ #include <fontconfig/fontconfig.h>
+
+-#include <X11/Xlibint.h> /* For XESetCloseDisplay */
+ #include <X11/extensions/Xrender.h>
+
+ static int
+@@ -133,7 +132,7 @@ get_integer_default (Display *dpy,
+ #endif
+
+ static void
+-_cairo_xlib_init_screen_font_options (cairo_xlib_screen_info_t *info)
++_cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *info)
+ {
+ cairo_bool_t xft_hinting;
+ cairo_bool_t xft_antialias;
+@@ -143,23 +142,23 @@ _cairo_xlib_init_screen_font_options (ca
+ cairo_subpixel_order_t subpixel_order;
+ cairo_hint_style_t hint_style;
+
+- if (!get_boolean_default (info->display, "antialias", &xft_antialias))
++ if (!get_boolean_default (dpy, "antialias", &xft_antialias))
+ xft_antialias = TRUE;
+
+- if (!get_boolean_default (info->display, "hinting", &xft_hinting))
++ if (!get_boolean_default (dpy, "hinting", &xft_hinting))
+ xft_hinting = TRUE;
+
+- if (!get_integer_default (info->display, "hintstyle", &xft_hintstyle))
++ if (!get_integer_default (dpy, "hintstyle", &xft_hintstyle))
+ xft_hintstyle = FC_HINT_FULL;
+
+- if (!get_integer_default (info->display, "rgba", &xft_rgba))
++ if (!get_integer_default (dpy, "rgba", &xft_rgba))
+ {
+ xft_rgba = FC_RGBA_UNKNOWN;
+
+ #if RENDER_MAJOR > 0 || RENDER_MINOR >= 6
+ if (info->has_render)
+ {
+- int render_order = XRenderQuerySubpixelOrder (info->display,
++ int render_order = XRenderQuerySubpixelOrder (dpy,
+ XScreenNumberOfScreen (info->screen));
+
+ switch (render_order)
+@@ -243,285 +242,165 @@ _cairo_xlib_init_screen_font_options (ca
+ cairo_font_options_set_hint_metrics (&info->font_options, CAIRO_HINT_METRICS_ON);
+ }
+
+-static cairo_xlib_screen_info_t *_cairo_xlib_screen_list = NULL;
+-
+-/* NOTE: This function must be called with _cairo_xlib_screen_mutex held. */
+-static void
+-_cairo_xlib_call_close_display_hooks (cairo_xlib_screen_info_t *info)
+-{
+- /* call all registered shutdown routines */
+- while (info->close_display_hooks != NULL) {
+- cairo_xlib_hook_t *hooks = info->close_display_hooks;
+- info->close_display_hooks = NULL;
+-
+- /* drop the list mutex whilst calling the hooks */
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
+- do {
+- cairo_xlib_hook_t *hook = hooks;
+- hooks = hook->next;
+-
+- hook->func (info->display, hook->data);
+-
+- free (hook);
+- } while (hooks != NULL);
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
+- }
+-}
+-
+-static void
+-_cairo_xlib_screen_info_reference_lock_held (cairo_xlib_screen_info_t *info)
+-{
+- assert (info->ref_count > 0);
+- info->ref_count++;
+-}
+-
+ cairo_xlib_screen_info_t *
+ _cairo_xlib_screen_info_reference (cairo_xlib_screen_info_t *info)
+ {
+ if (info == NULL)
+ return NULL;
+
+- /* use our global mutex until we get a real atomic inc */
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
+-
+- _cairo_xlib_screen_info_reference_lock_held (info);
+-
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
++ assert (info->ref_count > 0);
++ info->ref_count++;
+
+ return info;
+ }
+
+-static void
+-_cairo_xlib_screen_info_destroy_lock_held (cairo_xlib_screen_info_t *info)
++void
++_cairo_xlib_screen_info_close_display (cairo_xlib_screen_info_t *info)
+ {
+- assert (info->ref_count > 0);
+- if (--info->ref_count)
+- return;
++ int i;
+
+- _cairo_xlib_call_close_display_hooks (info);
+- free (info);
++ for (i = 0; i < ARRAY_LENGTH (info->gc); i++) {
++ if (info->gc[i] != NULL) {
++ XFreeGC (info->display->display, info->gc[i]);
++ info->gc[i] = NULL;
++ }
++ }
+ }
+
+ void
+ _cairo_xlib_screen_info_destroy (cairo_xlib_screen_info_t *info)
+ {
++ cairo_xlib_screen_info_t **prev;
++ cairo_xlib_screen_info_t *list;
++
+ if (info == NULL)
+ return;
+
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
+-
+- _cairo_xlib_screen_info_destroy_lock_held (info);
+-
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
+-}
+-
+-static int
+-_cairo_xlib_close_display (Display *dpy, XExtCodes *codes)
+-{
+- cairo_xlib_screen_info_t *info, **prev, *next;
++ assert (info->ref_count > 0);
++ if (--info->ref_count)
++ return;
+
+- /*
+- * Unhook from the global list
+- */
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
+-
+- prev = &_cairo_xlib_screen_list;
+- for (info = _cairo_xlib_screen_list; info; info = next) {
+- next = info->next;
+- if (info->display == dpy) {
+- /* trigger the hooks explicitly as we know the display is closing */
+- _cairo_xlib_call_close_display_hooks (info);
+- _cairo_xlib_screen_info_destroy_lock_held (info);
+- *prev = next;
+- } else {
+- prev = &info->next;
++ CAIRO_MUTEX_LOCK (info->display->mutex);
++ for (prev = &info->display->screens; (list = *prev); prev = &list->next) {
++ if (list == info) {
++ *prev = info->next;
++ break;
+ }
+ }
+- *prev = NULL;
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
+-
+- /* Return value in accordance with requirements of
+- * XESetCloseDisplay */
+- return 0;
+-}
+-
+-static void
+-_cairo_xlib_screen_info_reset (void)
+-{
+- /*
+- * Delete everything in the list.
+- */
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
++ assert (list != NULL);
++ CAIRO_MUTEX_UNLOCK (info->display->mutex);
+
+- while (_cairo_xlib_screen_list != NULL) {
+- cairo_xlib_screen_info_t *info = _cairo_xlib_screen_list;
+- _cairo_xlib_screen_list = info->next;
+- _cairo_xlib_screen_info_destroy_lock_held (info);
+- }
++ _cairo_xlib_screen_info_close_display (info);
+
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
++ _cairo_xlib_display_destroy (info->display);
+
++ free (info);
+ }
+
+-static cairo_xlib_screen_info_t *
+-_cairo_xlib_screen_info_get_lock_held (Display *dpy, Screen *screen)
++cairo_xlib_screen_info_t *
++_cairo_xlib_screen_info_get (Display *dpy, Screen *screen)
+ {
+- cairo_xlib_screen_info_t *info;
+- cairo_xlib_screen_info_t **prev;
+- int event_base, error_base;
+- XExtCodes *codes;
+- cairo_bool_t seen_display = FALSE;
++ cairo_xlib_display_t *display;
++ cairo_xlib_screen_info_t *info = NULL, **prev;
+
+- for (prev = &_cairo_xlib_screen_list; (info = *prev); prev = &(*prev)->next)
+- {
+- if (info->display == dpy) {
+- seen_display = TRUE;
+- if (info->screen == screen) {
+- /*
+- * MRU the list
+- */
+- if (prev != &_cairo_xlib_screen_list) {
+- *prev = info->next;
+- info->next = _cairo_xlib_screen_list;
+- _cairo_xlib_screen_list = info;
+- }
+- break;
+- }
+- }
+- }
+-
+- if (info)
+- return info;
+-
+- info = malloc (sizeof (cairo_xlib_screen_info_t));
+- if (!info)
++ display = _cairo_xlib_display_get (dpy);
++ if (display == NULL)
+ return NULL;
+
+- if (!seen_display) {
+- codes = XAddExtension (dpy);
+- if (!codes) {
+- free (info);
+- return NULL;
+- }
++ CAIRO_MUTEX_LOCK (display->mutex);
++ if (display->closed) {
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++ goto DONE;
++ }
+
+- XESetCloseDisplay (dpy, codes->extension, _cairo_xlib_close_display);
++ for (prev = &display->screens; (info = *prev); prev = &(*prev)->next) {
++ if (info->screen == screen) {
++ /*
++ * MRU the list
++ */
++ if (prev != &display->screens) {
++ *prev = info->next;
++ info->next = display->screens;
++ display->screens = info;
++ }
++ break;
++ }
+ }
++ CAIRO_MUTEX_UNLOCK (display->mutex);
+
+- info->ref_count = 1;
+- info->display = dpy;
+- info->screen = screen;
+- info->close_display_hooks = NULL;
+- info->has_render = FALSE;
+- _cairo_font_options_init_default (&info->font_options);
++ if (info != NULL) {
++ info = _cairo_xlib_screen_info_reference (info);
++ } else {
++ info = malloc (sizeof (cairo_xlib_screen_info_t));
++ if (info != NULL) {
++ info->ref_count = 1;
++ info->display = _cairo_xlib_display_reference (display);
++ info->screen = screen;
++ info->has_render = FALSE;
++ _cairo_font_options_init_default (&info->font_options);
++ memset (info->gc, 0, sizeof (info->gc));
++
++ if (screen) {
++ int event_base, error_base;
++ info->has_render = (XRenderQueryExtension (dpy, &event_base, &error_base) &&
++ (XRenderFindVisualFormat (dpy, DefaultVisual (dpy, DefaultScreen (dpy))) != 0));
++ _cairo_xlib_init_screen_font_options (dpy, info);
++ }
+
+- if (screen) {
+- info->has_render = (XRenderQueryExtension (dpy, &event_base, &error_base) &&
+- (XRenderFindVisualFormat (dpy, DefaultVisual (dpy, DefaultScreen (dpy))) != 0));
+- _cairo_xlib_init_screen_font_options (info);
++ CAIRO_MUTEX_LOCK (display->mutex);
++ info->next = display->screens;
++ display->screens = info;
++ CAIRO_MUTEX_UNLOCK (display->mutex);
++ }
+ }
+
+- info->next = _cairo_xlib_screen_list;
+- _cairo_xlib_screen_list = info;
++DONE:
++ _cairo_xlib_display_destroy (display);
+
+ return info;
+ }
+-cairo_xlib_screen_info_t *
+-_cairo_xlib_screen_info_get (Display *dpy, Screen *screen)
+-{
+- cairo_xlib_screen_info_t *info;
+
+- /* There is an apparent deadlock between this mutex and the
+- * mutex for the display, but it's actually safe. For the
+- * app to call XCloseDisplay() while any other thread is
+- * inside this function would be an error in the logic
+- * app, and the CloseDisplay hook is the only other place we
+- * acquire this mutex.
+- */
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
+-
+- info = _cairo_xlib_screen_info_get_lock_held (dpy, screen);
+- if (info != NULL)
+- _cairo_xlib_screen_info_reference_lock_held (info);
+-
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
+-
+- return info;
++static int
++depth_to_index (int depth)
++{
++ switch(depth){
++ case 1: return 0;
++ case 8: return 1;
++ case 15: return 2;
++ case 16: return 3;
++ case 24: return 4;
++ case 32: return 5;
++ }
++ return 0;
+ }
+
+-cairo_bool_t
+-_cairo_xlib_add_close_display_hook (Display *dpy, void (*func) (Display *, void *), void *data, void *key)
++GC
++_cairo_xlib_screen_get_gc (cairo_xlib_screen_info_t *info, int depth)
+ {
+- cairo_xlib_screen_info_t *info;
+- cairo_xlib_hook_t *hook;
+- cairo_xlib_hook_t **prev;
+- cairo_bool_t success = FALSE;
+
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
++ GC gc;
+
+- info = _cairo_xlib_screen_info_get_lock_held (dpy, NULL);
+- if (!info)
+- goto unlock;
++ depth = depth_to_index (depth);
+
+- for (prev = &info->close_display_hooks; (hook = *prev); prev = &hook->next)
+- {
+- if (hook->key == key) {
+- /*
+- * MRU the list
+- */
+- if (prev != &info->close_display_hooks) {
+- *prev = hook->next;
+- hook->next = info->close_display_hooks;
+- info->close_display_hooks = hook;
+- }
+- break;
+- }
+- }
++ gc = info->gc[depth];
++ info->gc[depth] = NULL;
+
+- if (!hook) {
+- hook = malloc (sizeof (cairo_xlib_hook_t));
+- if (!hook)
+- goto unlock;
+- hook->func = func;
+- hook->data = data;
+- hook->key = key;
+- hook->next = info->close_display_hooks;
+- info->close_display_hooks = hook;
+- }
+-
+- success = TRUE;
+- unlock:
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
+- return success;
++ return gc;
+ }
+
+ void
+-_cairo_xlib_remove_close_display_hook (Display *dpy, void *key)
++_cairo_xlib_screen_put_gc (cairo_xlib_screen_info_t *info, int depth, GC gc)
+ {
+- cairo_xlib_screen_info_t *info;
+- cairo_xlib_hook_t *hook;
+- cairo_xlib_hook_t **prev;
+-
+- CAIRO_MUTEX_LOCK (_cairo_xlib_screen_mutex);
++ depth = depth_to_index (depth);
+
+- info = _cairo_xlib_screen_info_get_lock_held (dpy, NULL);
+- if (!info)
+- goto unlock;
+-
+- for (prev = &info->close_display_hooks; (hook = *prev); prev = &hook->next)
+- {
+- if (hook->key == key) {
+- *prev = hook->next;
+- free (hook);
+- break;
+- }
++ if (info->gc[depth] != NULL) {
++ cairo_status_t status;
++ status = _cairo_xlib_display_queue_work (info->display,
++ (cairo_xlib_notify_func) XFreeGC,
++ info->gc[depth],
++ NULL);
++ (void) status;
+ }
+
+-unlock:
+- CAIRO_MUTEX_UNLOCK (_cairo_xlib_screen_mutex);
+-}
+-
+-void
+-_cairo_xlib_screen_reset_static_data (void)
+-{
+- _cairo_xlib_screen_info_reset ();
++ info->gc[depth] = gc;
+ }
+--- a/src/cairo-xlib-surface.c
++++ b/src/cairo-xlib-surface.c
+@@ -127,8 +127,17 @@ struct _cairo_xlib_surface {
+ int num_clip_rects;
+
+ XRenderPictFormat *xrender_format;
++ cairo_filter_t filter;
++ int repeat;
++ XTransform xtransform;
+ };
+
++static const XTransform identity = { {
++ { 1 << 16, 0x00000, 0x00000 },
++ { 0x00000, 1 << 16, 0x00000 },
++ { 0x00000, 0x00000, 1 << 16 },
++} };
++
+ #define CAIRO_SURFACE_RENDER_AT_LEAST(surface, major, minor) \
+ (((surface)->render_major > major) || \
+ (((surface)->render_major == major) && ((surface)->render_minor >= minor)))
+@@ -281,6 +290,8 @@ _cairo_xlib_surface_create_similar (void
+ cairo_xlib_surface_t *surface;
+ Pixmap pix;
+
++ _cairo_xlib_display_notify (src->screen_info->display);
++
+ /* Start by examining the surface's XRenderFormat, or if it
+ * doesn't have one, then look one up through its visual (in the
+ * case of a bitmap, it won't even have that). */
+@@ -322,21 +333,75 @@ _cairo_xlib_surface_create_similar (void
+ return &surface->base;
+ }
+
++static void
++_cairo_xlib_reset_clip_mask (Display *dpy, GC gc)
++{
++ XSetClipMask(dpy, gc, None);
++}
++
+ static cairo_status_t
+ _cairo_xlib_surface_finish (void *abstract_surface)
+ {
+ cairo_xlib_surface_t *surface = abstract_surface;
+- if (surface->dst_picture != None)
+- XRenderFreePicture (surface->dpy, surface->dst_picture);
+-
+- if (surface->src_picture != None)
+- XRenderFreePicture (surface->dpy, surface->src_picture);
+-
+- if (surface->owns_pixmap)
+- XFreePixmap (surface->dpy, surface->drawable);
+-
+- if (surface->gc != NULL)
+- XFreeGC (surface->dpy, surface->gc);
++ cairo_xlib_display_t *display = surface->screen_info ?
++ surface->screen_info->display :
++ NULL;
++ cairo_status_t status = CAIRO_STATUS_SUCCESS;
++
++ if (surface->dst_picture != None) {
++ cairo_status_t status2;
++ assert (display != NULL);
++ status2 = _cairo_xlib_display_queue_resource (display,
++ XRenderFreePicture,
++ surface->dst_picture);
++ if (status2 == CAIRO_STATUS_SUCCESS)
++ surface->dst_picture = None;
++ else if (status == CAIRO_STATUS_SUCCESS)
++ status = status2;
++ }
++
++ if (surface->src_picture != None) {
++ cairo_status_t status2;
++ assert (display != NULL);
++ status2 = _cairo_xlib_display_queue_resource (display,
++ XRenderFreePicture,
++ surface->src_picture);
++ if (status2 == CAIRO_STATUS_SUCCESS)
++ surface->src_picture = None;
++ else if (status == CAIRO_STATUS_SUCCESS)
++ status = status2;
++ }
++
++ if (surface->owns_pixmap) {
++ cairo_status_t status2;
++ assert (display != NULL);
++ status2 = _cairo_xlib_display_queue_resource (display,
++ (cairo_xlib_notify_resource_func) XFreePixmap,
++ surface->drawable);
++ if (status2 == CAIRO_STATUS_SUCCESS) {
++ surface->owns_pixmap = FALSE;
++ surface->drawable = None;
++ } else if (status == CAIRO_STATUS_SUCCESS)
++ status = status2;
++ }
++
++ if (surface->gc != NULL) {
++ _cairo_xlib_screen_put_gc (surface->screen_info,
++ surface->depth,
++ surface->gc);
++ if (surface->have_clip_rects) {
++ cairo_status_t status2;
++ assert (display != NULL);
++ status2 = _cairo_xlib_display_queue_work (display,
++ (cairo_xlib_notify_func) _cairo_xlib_reset_clip_mask,
++ surface->gc,
++ NULL);
++ if (status2 == CAIRO_STATUS_SUCCESS)
++ surface->gc = NULL;
++ else if (status == CAIRO_STATUS_SUCCESS)
++ status = status2;
++ }
++ }
+
+ if (surface->clip_rects != NULL)
+ free (surface->clip_rects);
+@@ -344,9 +409,12 @@ _cairo_xlib_surface_finish (void *abstra
+ if (surface->screen_info != NULL)
+ _cairo_xlib_screen_info_destroy (surface->screen_info);
+
+- surface->dpy = NULL;
++ if (surface->dpy != NULL) {
++ _cairo_xlib_remove_close_display_hooks (surface->dpy, surface);
++ surface->dpy = NULL;
++ }
+
+- return CAIRO_STATUS_SUCCESS;
++ return status;
+ }
+
+ static int
+@@ -747,11 +815,15 @@ _cairo_xlib_surface_ensure_gc (cairo_xli
+ if (surface->gc)
+ return CAIRO_STATUS_SUCCESS;
+
+- gcv.graphics_exposures = False;
+- surface->gc = XCreateGC (surface->dpy, surface->drawable,
+- GCGraphicsExposures, &gcv);
+- if (!surface->gc)
+- return CAIRO_STATUS_NO_MEMORY;
++ surface->gc = _cairo_xlib_screen_get_gc (surface->screen_info,
++ surface->depth);
++ if (surface->gc == NULL) {
++ gcv.graphics_exposures = False;
++ surface->gc = XCreateGC (surface->dpy, surface->drawable,
++ GCGraphicsExposures, &gcv);
++ if (!surface->gc)
++ return CAIRO_STATUS_NO_MEMORY;
++ }
+
+ _cairo_xlib_surface_set_gc_clip_rects (surface);
+
+@@ -814,6 +886,8 @@ _cairo_xlib_surface_acquire_source_image
+ cairo_image_surface_t *image;
+ cairo_status_t status;
+
++ _cairo_xlib_display_notify (surface->screen_info->display);
++
+ status = _get_image_surface (surface, NULL, &image, NULL);
+ if (status)
+ return status;
+@@ -843,6 +917,8 @@ _cairo_xlib_surface_acquire_dest_image (
+ cairo_image_surface_t *image;
+ cairo_status_t status;
+
++ _cairo_xlib_display_notify (surface->screen_info->display);
++
+ status = _get_image_surface (surface, interest_rect, &image, image_rect_out);
+ if (status)
+ return status;
+@@ -894,6 +970,8 @@ _cairo_xlib_surface_clone_similar (void
+ cairo_xlib_surface_t *clone;
+ cairo_status_t status;
+
++ _cairo_xlib_display_notify (surface->screen_info->display);
++
+ if (src->backend == surface->base.backend ) {
+ cairo_xlib_surface_t *xlib_src = (cairo_xlib_surface_t *)src;
+
+@@ -952,19 +1030,17 @@ _cairo_xlib_surface_set_matrix (cairo_xl
+
+ if (!CAIRO_SURFACE_RENDER_HAS_PICTURE_TRANSFORM (surface))
+ {
+- static const XTransform identity = { {
+- { 1 << 16, 0x00000, 0x00000 },
+- { 0x00000, 1 << 16, 0x00000 },
+- { 0x00000, 0x00000, 1 << 16 },
+- } };
+-
+ if (memcmp (&xtransform, &identity, sizeof (XTransform)) == 0)
+ return CAIRO_STATUS_SUCCESS;
+
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+ }
+
++ if (memcmp (&xtransform, &surface->xtransform, sizeof (XTransform)) == 0)
++ return CAIRO_STATUS_SUCCESS;
++
+ XRenderSetPictureTransform (surface->dpy, surface->src_picture, &xtransform);
++ surface->xtransform = xtransform;
+
+ return CAIRO_STATUS_SUCCESS;
+ }
+@@ -978,6 +1054,9 @@ _cairo_xlib_surface_set_filter (cairo_xl
+ if (!surface->src_picture)
+ return CAIRO_STATUS_SUCCESS;
+
++ if (surface->filter == filter)
++ return CAIRO_STATUS_SUCCESS;
++
+ if (!CAIRO_SURFACE_RENDER_HAS_FILTERS (surface))
+ {
+ if (filter == CAIRO_FILTER_FAST || filter == CAIRO_FILTER_NEAREST)
+@@ -1015,6 +1094,7 @@ _cairo_xlib_surface_set_filter (cairo_xl
+
+ XRenderSetPictureFilter (surface->dpy, surface->src_picture,
+ (char *) render_filter, NULL, 0);
++ surface->filter = filter;
+
+ return CAIRO_STATUS_SUCCESS;
+ }
+@@ -1028,10 +1108,14 @@ _cairo_xlib_surface_set_repeat (cairo_xl
+ if (!surface->src_picture)
+ return CAIRO_STATUS_SUCCESS;
+
++ if (surface->repeat == repeat)
++ return CAIRO_STATUS_SUCCESS;
++
+ mask = CPRepeat;
+ pa.repeat = repeat;
+
+ XRenderChangePicture (surface->dpy, surface->src_picture, mask, &pa);
++ surface->repeat = repeat;
+
+ return CAIRO_STATUS_SUCCESS;
+ }
+@@ -1327,6 +1411,8 @@ _cairo_xlib_surface_composite (cairo_ope
+ int itx, ity;
+ cairo_bool_t is_integer_translation;
+
++ _cairo_xlib_display_notify (dst->screen_info->display);
++
+ if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (dst))
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+
+@@ -1466,6 +1552,8 @@ _cairo_xlib_surface_fill_rectangles (voi
+ cairo_xlib_surface_t *surface = abstract_surface;
+ XRenderColor render_color;
+
++ _cairo_xlib_display_notify (surface->screen_info->display);
++
+ if (!CAIRO_SURFACE_RENDER_HAS_FILL_RECTANGLE (surface))
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+
+@@ -1598,6 +1686,8 @@ _cairo_xlib_surface_composite_trapezoids
+ int render_src_x, render_src_y;
+ XRenderPictFormat *pict_format;
+
++ _cairo_xlib_display_notify (dst->screen_info->display);
++
+ if (!CAIRO_SURFACE_RENDER_HAS_TRAPEZOIDS (dst))
+ return CAIRO_INT_STATUS_UNSUPPORTED;
+
+@@ -1707,6 +1797,8 @@ _cairo_xlib_surface_set_clip_region (voi
+ {
+ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface;
+
++ _cairo_xlib_display_notify (surface->screen_info->display);
++
+ if (surface->clip_rects) {
+ free (surface->clip_rects);
+ surface->clip_rects = NULL;
+@@ -1793,6 +1885,16 @@ static void
+ _cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
+ cairo_scaled_font_t *scaled_font);
+
++static cairo_bool_t
++_cairo_xlib_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_xlib_surface_t *a = (cairo_xlib_surface_t *) surface_a;
++ cairo_xlib_surface_t *b = (cairo_xlib_surface_t *) surface_b;
++
++ return _cairo_xlib_surface_same_screen (a, b);
++}
++
+ static const cairo_surface_backend_t cairo_xlib_surface_backend = {
+ CAIRO_SURFACE_TYPE_XLIB,
+ _cairo_xlib_surface_create_similar,
+@@ -1822,7 +1924,8 @@ static const cairo_surface_backend_t cai
+ NULL, /* stroke */
+ NULL, /* fill */
+ _cairo_xlib_surface_show_glyphs,
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_xlib_surface_is_compatible,
+ };
+
+ /**
+@@ -1839,6 +1942,44 @@ _cairo_surface_is_xlib (cairo_surface_t
+ return surface->backend == &cairo_xlib_surface_backend;
+ }
+
++static void
++_cairo_xlib_surface_detach_display (Display *dpy, void *data)
++{
++ cairo_xlib_surface_t *surface = data;
++
++ surface->dpy = NULL;
++
++ if (surface->dst_picture != None) {
++ XRenderFreePicture (dpy, surface->dst_picture);
++ _cairo_xlib_display_cancel_resource (surface->screen_info->display,
++ surface->dst_picture);
++ surface->dst_picture = None;
++ }
++
++ if (surface->src_picture != None) {
++ XRenderFreePicture (dpy, surface->src_picture);
++ _cairo_xlib_display_cancel_resource (surface->screen_info->display,
++ surface->src_picture);
++ surface->src_picture = None;
++ }
++
++ if (surface->owns_pixmap) {
++ XFreePixmap (dpy, surface->drawable);
++ _cairo_xlib_display_cancel_resource (surface->screen_info->display,
++ surface->drawable);
++ surface->drawable = None;
++ surface->owns_pixmap = FALSE;
++ }
++
++ if (surface->gc != NULL) {
++ assert (surface->screen_info != NULL);
++ XFreeGC (dpy, surface->gc);
++ _cairo_xlib_display_cancel_work (surface->screen_info->display,
++ surface->gc);
++ surface->gc = NULL;
++ }
++}
++
+ static cairo_surface_t *
+ _cairo_xlib_surface_create_internal (Display *dpy,
+ Drawable drawable,
+@@ -1865,6 +2006,14 @@ _cairo_xlib_surface_create_internal (Dis
+ return (cairo_surface_t*) &_cairo_surface_nil;
+ }
+
++ if (! _cairo_xlib_add_close_display_hook (dpy,
++ _cairo_xlib_surface_detach_display, surface, surface)) {
++ free (surface);
++ _cairo_xlib_screen_info_destroy (screen_info);
++ _cairo_error (CAIRO_STATUS_NO_MEMORY);
++ return (cairo_surface_t*) &_cairo_surface_nil;
++ }
++
+ if (xrender_format) {
+ depth = xrender_format->depth;
+ } else if (visual) {
+@@ -1935,6 +2084,9 @@ _cairo_xlib_surface_create_internal (Dis
+ surface->visual = visual;
+ surface->xrender_format = xrender_format;
+ surface->depth = depth;
++ surface->filter = (cairo_filter_t) -1; /* XXX XRender default? */
++ surface->repeat = FALSE;
++ surface->xtransform = identity;
+
+ surface->have_clip_rects = FALSE;
+ surface->clip_rects = NULL;
+@@ -2125,14 +2277,26 @@ cairo_xlib_surface_set_drawable (cairo_s
+ return;
+
+ if (surface->drawable != drawable) {
+- if (surface->dst_picture)
+- XRenderFreePicture (surface->dpy, surface->dst_picture);
++ if (surface->dst_picture != None) {
++ cairo_status_t status;
++ status = _cairo_xlib_display_queue_resource (
++ surface->screen_info->display,
++ XRenderFreePicture,
++ surface->dst_picture);
++ (void) status;
++ surface->dst_picture = None;
++ }
++
++ if (surface->src_picture != None) {
++ cairo_status_t status;
++ status = _cairo_xlib_display_queue_resource (
++ surface->screen_info->display,
++ XRenderFreePicture,
++ surface->src_picture);
++ (void) status;
+
+- if (surface->src_picture)
+- XRenderFreePicture (surface->dpy, surface->src_picture);
+-
+- surface->dst_picture = None;
+- surface->src_picture = None;
++ surface->src_picture = None;
++ }
+
+ surface->drawable = drawable;
+ }
+@@ -2310,7 +2474,7 @@ typedef struct _cairo_xlib_surface_font_
+
+ static void
+ _cairo_xlib_surface_remove_scaled_font (Display *dpy,
+- void *data)
++ void *data)
+ {
+ cairo_scaled_font_t *scaled_font = data;
+ cairo_xlib_surface_font_private_t *font_private;
+@@ -2322,8 +2486,18 @@ _cairo_xlib_surface_remove_scaled_font (
+ _cairo_scaled_font_reset_cache (scaled_font);
+ CAIRO_MUTEX_UNLOCK (scaled_font->mutex);
+
+- if (font_private) {
++ if (font_private != NULL) {
++ cairo_xlib_display_t *display;
++
+ XRenderFreeGlyphSet (font_private->dpy, font_private->glyphset);
++
++ display = _cairo_xlib_display_get (dpy);
++ if (display != NULL) {
++ _cairo_xlib_display_cancel_resource (display,
++ font_private->glyphset);
++ _cairo_xlib_display_destroy (display);
++ }
++
+ free (font_private);
+ }
+ }
+@@ -2363,12 +2537,34 @@ _cairo_xlib_surface_scaled_font_fini (ca
+ cairo_xlib_surface_font_private_t *font_private = scaled_font->surface_private;
+
+ if (font_private) {
+- _cairo_xlib_remove_close_display_hook (font_private->dpy, scaled_font);
+- XRenderFreeGlyphSet (font_private->dpy, font_private->glyphset);
++ cairo_xlib_display_t *display;
++
++ _cairo_xlib_remove_close_display_hooks (font_private->dpy, scaled_font);
++
++ display = _cairo_xlib_display_get (font_private->dpy);
++ if (display != NULL) {
++ cairo_status_t status = _cairo_xlib_display_queue_resource (display,
++ XRenderFreeGlyphSet,
++ font_private->glyphset);
++ (void) status; /* cannot propagate failure */
++ _cairo_xlib_display_destroy (display);
++ }
++
+ free (font_private);
+ }
+ }
+
++struct _cairo_xlib_render_free_glyphs {
++ GlyphSet glyphset;
++ unsigned long glyph_index;
++};
++static void _cairo_xlib_render_free_glyphs (Display *dpy, struct _cairo_xlib_render_free_glyphs *arg)
++{
++ XRenderFreeGlyphs (dpy,
++ arg->glyphset,
++ &arg->glyph_index, 1);
++}
++
+ static void
+ _cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
+ cairo_scaled_font_t *scaled_font)
+@@ -2376,10 +2572,23 @@ _cairo_xlib_surface_scaled_glyph_fini (c
+ cairo_xlib_surface_font_private_t *font_private = scaled_font->surface_private;
+
+ if (font_private != NULL && scaled_glyph->surface_private != NULL) {
+- unsigned long glyph_index = _cairo_scaled_glyph_index(scaled_glyph);
+- XRenderFreeGlyphs (font_private->dpy,
+- font_private->glyphset,
+- &glyph_index, 1);
++ cairo_xlib_display_t *display = _cairo_xlib_display_get (font_private->dpy);
++ if (display != NULL) {
++ struct _cairo_xlib_render_free_glyphs *arg = malloc (sizeof (*arg));
++ if (arg != NULL) {
++ cairo_status_t status;
++ arg->glyphset = font_private->glyphset;
++ arg->glyph_index = _cairo_scaled_glyph_index (scaled_glyph);
++ status = _cairo_xlib_display_queue_work (display,
++ (cairo_xlib_notify_func) _cairo_xlib_render_free_glyphs,
++ arg,
++ free);
++ (void) status; /* cannot propagate failure */
++ }
++
++ _cairo_xlib_display_destroy (display);
++
++ }
+ }
+ }
+
+@@ -2990,6 +3199,7 @@ _cairo_xlib_surface_show_glyphs (void
+ _cairo_pattern_fini (&solid_pattern.base);
+ BAIL0:
+ _cairo_scaled_font_thaw_cache (scaled_font);
++ _cairo_xlib_display_notify (dst->screen_info->display);
+
+ return status;
+ }
+--- a/src/cairoint.h
++++ b/src/cairoint.h
+@@ -172,6 +172,11 @@ do { \
+ assert (NOT_REACHED); \
+ } while (0)
+
++/* Performs a compile time assert */
++#define CAIRO_STATIC_ASSERT(condition) _CAIRO_STATIC_ASSERT_IMPL(condition, __LINE__)
++#define _CAIRO_STATIC_ASSERT_IMPL(condition, line) _CAIRO_STATIC_ASSERT_IMPL2(condition, line)
++#define _CAIRO_STATIC_ASSERT_IMPL2(condition, line) typedef int _cairo_static_assert_line_##line[(condition) ? 1 : -1]
++
+ #define CAIRO_REF_COUNT_INVALID ((unsigned int) -1)
+
+ #include "cairo-mutex-private.h"
+@@ -591,12 +596,6 @@ _cairo_font_reset_static_data (void);
+ cairo_private void
+ _cairo_ft_font_reset_static_data (void);
+
+-cairo_private void
+-_cairo_xlib_surface_reset_static_data (void);
+-
+-cairo_private void
+-_cairo_xlib_screen_reset_static_data (void);
+-
+ /* the font backend interface */
+
+ struct _cairo_unscaled_font_backend {
+@@ -974,6 +973,10 @@ struct _cairo_surface_backend {
+
+ cairo_surface_t *
+ (*snapshot) (void *surface);
++
++ cairo_bool_t
++ (*is_compatible) (void *surface_a,
++ void *surface_b);
+ };
+
+ typedef struct _cairo_format_masks {
+@@ -1848,7 +1851,8 @@ _cairo_surface_create_similar_solid (cai
+ cairo_content_t content,
+ int width,
+ int height,
+- const cairo_color_t *color);
++ const cairo_color_t *color,
++ cairo_pattern_t *pattern);
+
+ cairo_private void
+ _cairo_surface_init (cairo_surface_t *surface,
+@@ -1993,6 +1997,10 @@ _cairo_surface_clone_similar (cairo_surf
+ cairo_private cairo_surface_t *
+ _cairo_surface_snapshot (cairo_surface_t *surface);
+
++cairo_private cairo_bool_t
++_cairo_surface_is_compatible (cairo_surface_t *surface_a,
++ cairo_surface_t *surface_b);
++
+ cairo_private unsigned int
+ _cairo_surface_get_current_clip_serial (cairo_surface_t *surface);
+
+--- a/test/create-for-stream.c
++++ b/test/create-for-stream.c
+@@ -177,12 +177,14 @@ test_surface (const char *filename,
+ if (fread (file_contents, 1, wc.index, fp) != wc.index) {
+ cairo_test_log ("Failed to read %s: %s\n",
+ filename, strerror (errno));
++ fclose (fp);
+ return CAIRO_TEST_FAILURE;
+ }
+
+ if (memcmp (file_contents, wc.buffer, wc.index) != 0) {
+ cairo_test_log ("Stream based output differ from file output for %s\n",
+ filename);
++ fclose (fp);
+ return CAIRO_TEST_FAILURE;
+ }
+
+@@ -195,35 +197,36 @@ test_surface (const char *filename,
+ int
+ main (void)
+ {
+- cairo_test_status_t status;
++ cairo_test_status_t status = CAIRO_TEST_SUCCESS;
++ cairo_test_status_t test_status;
+
+ cairo_test_init ("create-for-stream");
+
+ #if CAIRO_HAS_PS_SURFACE
+- status = test_surface ("create-for-stream.ps",
+- cairo_ps_surface_create,
+- cairo_ps_surface_create_for_stream);
+- if (status != CAIRO_TEST_SUCCESS)
+- return status;
++ test_status = test_surface ("create-for-stream.ps",
++ cairo_ps_surface_create,
++ cairo_ps_surface_create_for_stream);
++ if (status == CAIRO_TEST_SUCCESS)
++ status = test_status;
+ #endif
+
+ #if CAIRO_HAS_PDF_SURFACE
+- status = test_surface ("create-for-stream.pdf",
+- cairo_pdf_surface_create,
+- cairo_pdf_surface_create_for_stream);
+- if (status != CAIRO_TEST_SUCCESS)
+- return status;
++ test_status = test_surface ("create-for-stream.pdf",
++ cairo_pdf_surface_create,
++ cairo_pdf_surface_create_for_stream);
++ if (status == CAIRO_TEST_SUCCESS)
++ status = test_status;
+ #endif
+
+ #if CAIRO_HAS_SVG_SURFACE
+- status = test_surface ("create-for-stream.svg",
+- cairo_svg_surface_create,
+- cairo_svg_surface_create_for_stream);
+- if (status != CAIRO_TEST_SUCCESS)
+- return status;
++ test_status = test_surface ("create-for-stream.svg",
++ cairo_svg_surface_create,
++ cairo_svg_surface_create_for_stream);
++ if (status == CAIRO_TEST_SUCCESS)
++ status = test_status;
+ #endif
+
+ cairo_test_fini ();
+
+- return CAIRO_TEST_SUCCESS;
++ return status;
+ }
diff --git a/recipes/cairo/cairo-1.6.4/configure_fix.patch b/recipes/cairo/cairo-1.6.4/configure_fix.patch
new file mode 100644
index 0000000000..44b59867f1
--- /dev/null
+++ b/recipes/cairo/cairo-1.6.4/configure_fix.patch
@@ -0,0 +1,70 @@
+Libtool 2.2.2 can't cope unless the LT_ variables are marked as AC_SUBST
+as otherwise autofoo tries to expand them, fails and gets upset.
+
+You can't conditionally add AC_PROG_CXX to a configure.ac file since the
+mere mention of it triggers some internals which then get upset it if
+wasn't really called at configure time.
+
+Referring to a .cpp file in Makefiles without calling AC_PROG_CXX is
+now also a fatal error. Easiest fix is to drop the CXX stuff entirely.
+
+RP - 14/4/08
+
+---
+ boilerplate/Makefile.am | 1 -
+ configure.in | 6 +++---
+ 2 files changed, 3 insertions(+), 4 deletions(-)
+
+--- cairo-1.6.4.orig/boilerplate/Makefile.am
++++ cairo-1.6.4/boilerplate/Makefile.am
+@@ -11,11 +11,10 @@ libcairoboilerplate_la_SOURCES = \
+ xmalloc.c \
+ xmalloc.h
+ libcairoboilerplate_la_LIBADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD)
+
+ if CAIRO_HAS_BEOS_SURFACE
+-libcairoboilerplate_la_SOURCES += cairo-boilerplate-beos.cpp
+ libcairoboilerplate_la_SOURCES += cairo-boilerplate-beos-private.h
+ # BeOS system headers trigger this warning
+ libcairoboilerplate_la_CXXFLAGS = -Wno-multichar
+ endif
+
+--- cairo-1.6.4.orig/configure.in
++++ cairo-1.6.4/configure.in
+@@ -25,19 +25,22 @@ dnl ====================================
+
+ # libtool shared library version
+
+ # Increment if the interface has additions, changes, removals.
+ LT_CURRENT=19
++AC_SUBST(LT_CURRENT)
+
+ # Increment any time the source changes; set to
+ # 0 if you increment CURRENT
+ LT_REVISION=5
++AC_SUBST(LT_REVISION)
+
+ # Increment if any interfaces have been added; set to 0
+ # if any interfaces have been removed. removal has
+ # precedence over adding, so set to 0 if both happened.
+ LT_AGE=17
++AC_SUBST(LT_AGE)
+
+ dnl ===========================================================================
+
+ VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE"
+ AC_SUBST(VERSION_INFO)
+@@ -442,13 +445,10 @@ CAIRO_BACKEND_ENABLE(beos, BeOS/Zeta, be
+ use_beos="no (requires a BeOS platform)"
+ ;;
+ esac
+ ])
+
+-if test "x$use_beos" = "xyes"; then
+- AC_PROG_CXX
+-fi
+
+ dnl ===========================================================================
+
+ CAIRO_BACKEND_ENABLE(png, PNG, png, PNG_FUNCTIONS, yes, [
+ use_png=no
diff --git a/recipes/cairo/cairo-directfb-1.6.4/configure_fix.patch b/recipes/cairo/cairo-directfb-1.6.4/configure_fix.patch
new file mode 100644
index 0000000000..44b59867f1
--- /dev/null
+++ b/recipes/cairo/cairo-directfb-1.6.4/configure_fix.patch
@@ -0,0 +1,70 @@
+Libtool 2.2.2 can't cope unless the LT_ variables are marked as AC_SUBST
+as otherwise autofoo tries to expand them, fails and gets upset.
+
+You can't conditionally add AC_PROG_CXX to a configure.ac file since the
+mere mention of it triggers some internals which then get upset it if
+wasn't really called at configure time.
+
+Referring to a .cpp file in Makefiles without calling AC_PROG_CXX is
+now also a fatal error. Easiest fix is to drop the CXX stuff entirely.
+
+RP - 14/4/08
+
+---
+ boilerplate/Makefile.am | 1 -
+ configure.in | 6 +++---
+ 2 files changed, 3 insertions(+), 4 deletions(-)
+
+--- cairo-1.6.4.orig/boilerplate/Makefile.am
++++ cairo-1.6.4/boilerplate/Makefile.am
+@@ -11,11 +11,10 @@ libcairoboilerplate_la_SOURCES = \
+ xmalloc.c \
+ xmalloc.h
+ libcairoboilerplate_la_LIBADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD)
+
+ if CAIRO_HAS_BEOS_SURFACE
+-libcairoboilerplate_la_SOURCES += cairo-boilerplate-beos.cpp
+ libcairoboilerplate_la_SOURCES += cairo-boilerplate-beos-private.h
+ # BeOS system headers trigger this warning
+ libcairoboilerplate_la_CXXFLAGS = -Wno-multichar
+ endif
+
+--- cairo-1.6.4.orig/configure.in
++++ cairo-1.6.4/configure.in
+@@ -25,19 +25,22 @@ dnl ====================================
+
+ # libtool shared library version
+
+ # Increment if the interface has additions, changes, removals.
+ LT_CURRENT=19
++AC_SUBST(LT_CURRENT)
+
+ # Increment any time the source changes; set to
+ # 0 if you increment CURRENT
+ LT_REVISION=5
++AC_SUBST(LT_REVISION)
+
+ # Increment if any interfaces have been added; set to 0
+ # if any interfaces have been removed. removal has
+ # precedence over adding, so set to 0 if both happened.
+ LT_AGE=17
++AC_SUBST(LT_AGE)
+
+ dnl ===========================================================================
+
+ VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE"
+ AC_SUBST(VERSION_INFO)
+@@ -442,13 +445,10 @@ CAIRO_BACKEND_ENABLE(beos, BeOS/Zeta, be
+ use_beos="no (requires a BeOS platform)"
+ ;;
+ esac
+ ])
+
+-if test "x$use_beos" = "xyes"; then
+- AC_PROG_CXX
+-fi
+
+ dnl ===========================================================================
+
+ CAIRO_BACKEND_ENABLE(png, PNG, png, PNG_FUNCTIONS, yes, [
+ use_png=no
diff --git a/recipes/cairo/cairo-directfb_1.4.8.bb b/recipes/cairo/cairo-directfb_1.4.8.bb
new file mode 100644
index 0000000000..ada747600e
--- /dev/null
+++ b/recipes/cairo/cairo-directfb_1.4.8.bb
@@ -0,0 +1,18 @@
+require cairo.inc
+RCONFLICTS = "cairo"
+RPROVIDES = "cairo-directfb"
+DEPENDS = "directfb libsm libpng fontconfig"
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+ file://cairo_directfb_is_similar-typo.patch;patch=1 \
+ "
+
+EXTRA_OECONF += " --enable-directfb \
+ --disable-xlib \
+ --disable-win32"
+
+LDFLAGS_append += " -ldirectfb"
+CFLAGS_append += " -I${STAGING_INCDIR}/directfb"
+
+PR = "r2"
+
+S = "${WORKDIR}/cairo-${PV}"
diff --git a/recipes/cairo/cairo-directfb_1.6.4.bb b/recipes/cairo/cairo-directfb_1.6.4.bb
new file mode 100644
index 0000000000..a8b3f0fc78
--- /dev/null
+++ b/recipes/cairo/cairo-directfb_1.6.4.bb
@@ -0,0 +1,17 @@
+require cairo.inc
+RCONFLICTS = "cairo"
+RPROVIDES = "cairo-directfb"
+DEPENDS = "directfb pixman libsm libpng fontconfig"
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+ file://configure_fix.patch;patch=1 "
+
+EXTRA_OECONF += " --enable-directfb \
+ --disable-xlib \
+ --disable-win32"
+
+LDFLAGS_append += " -ldirectfb"
+CFLAGS_append += " -I${STAGING_INCDIR}/directfb"
+
+PR = "r0"
+
+S = "${WORKDIR}/cairo-${PV}"
diff --git a/recipes/cairo/cairo-fpu.inc b/recipes/cairo/cairo-fpu.inc
new file mode 100644
index 0000000000..bdaf789799
--- /dev/null
+++ b/recipes/cairo/cairo-fpu.inc
@@ -0,0 +1,6 @@
+
+def get_cairo_fpu_setting(bb, d):
+ if bb.data.getVar('TARGET_FPU', d, 1) in [ 'soft' ]:
+ return "--disable-some-floating-point"
+ return ""
+
diff --git a/recipes/cairo/cairo.inc b/recipes/cairo/cairo.inc
new file mode 100644
index 0000000000..3123fe6632
--- /dev/null
+++ b/recipes/cairo/cairo.inc
@@ -0,0 +1,15 @@
+SECTION = "libs"
+PRIORITY = "optional"
+DEPENDS = "virtual/libx11 pixman libsm libpng fontconfig libxrender"
+DESCRIPTION = "Cairo graphics library"
+LICENSE = "MPL LGPL"
+
+#check for TARGET_FPU=soft and inform configure of the result so it can disable some floating points
+require cairo-fpu.inc
+EXTRA_OECONF += "${@get_cairo_fpu_setting(bb, d)}"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/cairo_1.2.4.bb b/recipes/cairo/cairo_1.2.4.bb
new file mode 100644
index 0000000000..e274387195
--- /dev/null
+++ b/recipes/cairo/cairo_1.2.4.bb
@@ -0,0 +1,17 @@
+SECTION = "libs"
+PRIORITY = "optional"
+DEPENDS = "virtual/libx11 libpng fontconfig libxrender"
+DESCRIPTION = "Cairo graphics library"
+LICENSE = "MPL LGPL"
+PR = "r2"
+
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+ file://0001-Add-autoconf-macro-AX_C_FLOAT_WORDS_BIGENDIAN.diff;patch=1 \
+ file://0002-Change-_cairo_fixed_from_double-to-use-the-magic-number-technique.diff;patch=1 \
+ "
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/cairo_1.4.10.bb b/recipes/cairo/cairo_1.4.10.bb
new file mode 100644
index 0000000000..e89c0e6a9c
--- /dev/null
+++ b/recipes/cairo/cairo_1.4.10.bb
@@ -0,0 +1,9 @@
+require cairo.inc
+
+DEFAULT_PREFERENCE = "-1"
+
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+file://stats.patch;patch=1;p=1"
+
+PR = "r0"
+
diff --git a/recipes/cairo/cairo_1.4.14.bb b/recipes/cairo/cairo_1.4.14.bb
new file mode 100644
index 0000000000..b0f9fe8790
--- /dev/null
+++ b/recipes/cairo/cairo_1.4.14.bb
@@ -0,0 +1,9 @@
+require cairo.inc
+
+DEFAULT_PREFERENCE = "-1"
+
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+file://0001-Fix-for-a-memory-leak-in-pixman.patch;patch=1;p=1"
+
+PR = "r0"
+
diff --git a/recipes/cairo/cairo_1.4.8.bb b/recipes/cairo/cairo_1.4.8.bb
new file mode 100644
index 0000000000..845e14fc29
--- /dev/null
+++ b/recipes/cairo/cairo_1.4.8.bb
@@ -0,0 +1,6 @@
+require cairo.inc
+
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz"
+
+PR = "r0"
+
diff --git a/recipes/cairo/cairo_1.6.4.bb b/recipes/cairo/cairo_1.6.4.bb
new file mode 100644
index 0000000000..0c262b80ee
--- /dev/null
+++ b/recipes/cairo/cairo_1.6.4.bb
@@ -0,0 +1,9 @@
+require cairo.inc
+
+DEFAULT_PREFERENCE = "-1"
+
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+ file://configure_fix.patch;patch=1 "
+
+PR = "r4"
+
diff --git a/recipes/cairo/cairo_1.7.6.bb b/recipes/cairo/cairo_1.7.6.bb
new file mode 100644
index 0000000000..b90c2631d5
--- /dev/null
+++ b/recipes/cairo/cairo_1.7.6.bb
@@ -0,0 +1,9 @@
+require cairo.inc
+
+DEFAULT_PREFERENCE = "-1"
+
+SRC_URI = "http://cairographics.org/snapshots/cairo-${PV}.tar.gz \
+# file://configure_fix.patch;patch=1 \
+ "
+
+
diff --git a/recipes/cairo/cairo_1.8.0.bb b/recipes/cairo/cairo_1.8.0.bb
new file mode 100644
index 0000000000..b2d8e655f3
--- /dev/null
+++ b/recipes/cairo/cairo_1.8.0.bb
@@ -0,0 +1,6 @@
+require cairo.inc
+
+SRC_URI = "http://cairographics.org/releases/cairo-${PV}.tar.gz \
+ "
+
+
diff --git a/recipes/cairo/cairo_git.bb b/recipes/cairo/cairo_git.bb
new file mode 100644
index 0000000000..44212103a6
--- /dev/null
+++ b/recipes/cairo/cairo_git.bb
@@ -0,0 +1,24 @@
+#This is a development snapshot, so lets hint OE to use the releases
+DEFAULT_PREFERENCE = "-1"
+
+SECTION = "libs"
+PRIORITY = "optional"
+DEPENDS = "pixman virtual/libx11 libsm libpng fontconfig libxrender"
+DESCRIPTION = "Cairo graphics library"
+LICENSE = "MPL LGPL"
+
+PV = "1.5.3+git${SRCDATE}"
+
+SRC_URI = "git://git.cairographics.org/git/cairo;protocol=git \
+ "
+inherit autotools pkgconfig
+
+S = "${WORKDIR}/git"
+
+do_compile_append() {
+ cd ${S}/perf ; oe_runmake
+}
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/cairomm_1.2.4.bb b/recipes/cairo/cairomm_1.2.4.bb
new file mode 100644
index 0000000000..7796a44016
--- /dev/null
+++ b/recipes/cairo/cairomm_1.2.4.bb
@@ -0,0 +1,9 @@
+require cairo.inc
+
+DEPENDS = "cairo"
+DESCRIPTION = "C++ bindings for Cairo graphics library"
+PR = "r0"
+
+SRC_URI = "http://cairographics.org/releases/cairomm-${PV}.tar.gz"
+
+#EXTRA_OECONF = "--disable-docs"
diff --git a/recipes/cairo/files/cairo-surface-cache-3.patch b/recipes/cairo/files/cairo-surface-cache-3.patch
new file mode 100644
index 0000000000..ba714359a6
--- /dev/null
+++ b/recipes/cairo/files/cairo-surface-cache-3.patch
@@ -0,0 +1,371 @@
+diff --git a/src/cairo-clip.c b/src/cairo-clip.c
+diff --git a/src/cairo-color.c b/src/cairo-color.c
+index a348839..0688167 100644
+--- a/src/cairo-color.c
++++ b/src/cairo-color.c
+@@ -159,3 +159,10 @@ _cairo_color_get_rgba_premultiplied (cai
+ *blue = color->blue * color->alpha;
+ *alpha = color->alpha;
+ }
++
++cairo_bool_t
++_cairo_color_equal (cairo_color_t *color_a,
++ cairo_color_t *color_b)
++{
++ return (memcmp (color_a, color_b, sizeof (cairo_color_t)) == 0);
++}
+diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
+index 686510d..96ee212 100644
+--- a/src/cairo-directfb-surface.c
++++ b/src/cairo-directfb-surface.c
+@@ -1514,6 +1514,15 @@ _cairo_directfb_surface_show_glyphs ( vo
+ }
+ #endif /* DFB_SHOW_GLYPHS */
+
++static cairo_bool_t
++_cairo_directfb_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_directfb_surface_t *a = (cairo_directfb_surface_t*) surface_a;
++ cairo_directfb_surface_t *b = (cairo_directfb_surface_t*) surface_b;
++
++ return (a->dfb == b->dfb);
++}
+
+ static cairo_surface_backend_t cairo_directfb_surface_backend = {
+ CAIRO_SURFACE_TYPE_DIRECTFB, /*type*/
+@@ -1564,7 +1573,8 @@ #if DFB_SHOW_GLYPHS
+ #else
+ NULL, /* show_glyphs */
+ #endif
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_directfb_is_compatible
+ };
+
+
+diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
+diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c
+index f492739..79e0162 100644
+--- a/src/cairo-glitz-surface.c
++++ b/src/cairo-glitz-surface.c
+@@ -1799,6 +1799,19 @@ _cairo_glitz_surface_scaled_glyph_fini (
+ }
+ }
+
++static cairo_bool_t
++_cairo_glitz_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_glitz_surface_t *a = (cairo_glitz_surface_t*) surface_a;
++ cairo_glitz_surface_t *b = (cairo_glitz_surface_t*) surface_b;
++
++ glitz_drawable *drawable_a = glitz_surface_get_drawable (a->surface);
++ glitz_drawable *drawable_b = glitz_surface_get_drawable (b->surface);
++
++ return (drawable_a == drawable_b);
++}
++
+ #define FIXED_TO_FLOAT(f) (((glitz_float_t) (f)) / 65536)
+
+ static cairo_status_t
+@@ -2194,7 +2207,16 @@ static const cairo_surface_backend_t cai
+ _cairo_glitz_surface_flush,
+ NULL, /* mark_dirty_rectangle */
+ _cairo_glitz_surface_scaled_font_fini,
+- _cairo_glitz_surface_scaled_glyph_fini
++ _cairo_glitz_surface_scaled_glyph_fini,
++
++ NULL, /* paint */
++ NULL, /* mask */
++ NULL, /* stroke */
++ NULL, /* fill */
++ NULL, /* show_glyphs */
++
++ NULL, /* snapshot */
++ _cairo_glitz_surface_is_compatible
+ };
+
+ static const cairo_surface_backend_t *
+diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
+diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c
+diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
+index b488d1f..28f8561 100644
+--- a/src/cairo-pattern.c
++++ b/src/cairo-pattern.c
+@@ -1020,6 +1020,8 @@ _cairo_pattern_acquire_surface_for_gradi
+ return status;
+ }
+
++#define MAX_CACHE_SIZE 16
++
+ static cairo_int_status_t
+ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern,
+ cairo_surface_t *dst,
+@@ -1030,12 +1032,59 @@ _cairo_pattern_acquire_surface_for_solid
+ cairo_surface_t **out,
+ cairo_surface_attributes_t *attribs)
+ {
+- *out = _cairo_surface_create_similar_solid (dst,
+- CAIRO_CONTENT_COLOR_ALPHA,
+- 1, 1,
+- &pattern->color);
+- if ((*out)->status)
+- return CAIRO_STATUS_NO_MEMORY;
++ /* We have a small cache here, because we don't want to constantly
++ * recreate surfaces for simple solid colors */
++ static struct {
++ cairo_color_t color;
++ cairo_surface_t *surface;
++ } cache[MAX_CACHE_SIZE];
++ static int cache_size = 0;
++ static int i = 0;
++ CAIRO_MUTEX_DECLARE (cache_lock);
++
++ cairo_surface_t *surface;
++ cairo_status_t status;
++
++ CAIRO_MUTEX_LOCK (cache_lock);
++
++ /* Check cache first */
++ if (i < cache_size)
++ if (_cairo_color_equal (&cache[i].color, &pattern->color) &&
++ _cairo_surface_is_compatible (cache[i].surface, dst))
++ goto DONE;
++
++ for (i = 0; i < cache_size; i++)
++ if (_cairo_color_equal (&cache[i].color, &pattern->color) &&
++ _cairo_surface_is_compatible (cache[i].surface, dst))
++ goto DONE;
++
++ /* Not cached, need to create new */
++ surface = _cairo_surface_create_similar_solid (dst,
++ CAIRO_CONTENT_COLOR_ALPHA,
++ 1, 1,
++ &pattern->color);
++ if (surface->status) {
++ status = CAIRO_STATUS_NO_MEMORY;
++
++ goto UNLOCK;
++ }
++
++ /* Cache new */
++ if (cache_size < MAX_CACHE_SIZE)
++ cache_size++;
++ else {
++ i = rand () % MAX_CACHE_SIZE;
++
++ /* Evict old */
++ cairo_surface_destroy (cache[i].surface);
++ }
++
++ cache[i].color = pattern->color;
++ cache[i].surface = surface;
++
++DONE:
++
++ *out = cairo_surface_reference (cache[i].surface);
+
+ attribs->x_offset = attribs->y_offset = 0;
+ cairo_matrix_init_identity (&attribs->matrix);
+@@ -1043,7 +1092,13 @@ _cairo_pattern_acquire_surface_for_solid
+ attribs->filter = CAIRO_FILTER_NEAREST;
+ attribs->acquired = FALSE;
+
+- return CAIRO_STATUS_SUCCESS;
++ status = CAIRO_STATUS_SUCCESS;
++
++UNLOCK:
++
++ CAIRO_MUTEX_UNLOCK (cache_lock);
++
++ return status;
+ }
+
+ /**
+diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
+diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
+diff --git a/src/cairo-surface.c b/src/cairo-surface.c
+index 2bff0da..78cad9b 100644
+--- a/src/cairo-surface.c
++++ b/src/cairo-surface.c
+@@ -1078,6 +1078,32 @@ _cairo_surface_snapshot (cairo_surface_t
+ return _cairo_surface_fallback_snapshot (surface);
+ }
+
++/**
++ * _cairo_surface_is_compatible
++ * @surface_a: a #cairo_surface_t
++ * @surface_b: a #cairo_surface_t
++ *
++ * Find out whether the given surfaces share the same backend,
++ * and if so, whether they can be considered compatible.
++ *
++ * The definition of "compatible" depends on the backend. In the
++ * xlib case, it means the surfaces share the same display.
++ *
++ * Return value: TRUE if the surfaces are compatible.
++ **/
++cairo_bool_t
++_cairo_surface_is_compatible (cairo_surface_t *surface_a,
++ cairo_surface_t *surface_b)
++{
++ if (surface_a->backend != surface_b->backend)
++ return FALSE;
++
++ if (surface_a->backend->is_compatible)
++ return surface_a->backend->is_compatible (surface_a, surface_b);
++
++ return TRUE;
++}
++
+ cairo_status_t
+ _cairo_surface_composite (cairo_operator_t op,
+ cairo_pattern_t *src,
+diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
+index be7e706..81eb916 100644
+--- a/src/cairo-win32-surface.c
++++ b/src/cairo-win32-surface.c
+@@ -1609,6 +1609,16 @@ _cairo_win32_surface_show_glyphs (void
+ return (win_result) ? CAIRO_STATUS_SUCCESS : CAIRO_INT_STATUS_UNSUPPORTED;
+ }
+
++static cairo_bool_t
++_cairo_win32_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_win32_surface_t *a = (cairo_win32_surface_t*) surface_a;
++ cairo_win32_surface_t *b = (cairo_win32_surface_t*) surface_b;
++
++ return (a->dc == b->dc);
++}
++
+ #undef STACK_GLYPH_SIZE
+
+ /**
+@@ -1879,7 +1889,8 @@ static const cairo_surface_backend_t cai
+ NULL, /* fill */
+ _cairo_win32_surface_show_glyphs,
+
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_win32_surface_is_compatible
+ };
+
+ /*
+diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
+index 2fdf8a1..8df859d 100644
+--- a/src/cairo-xcb-surface.c
++++ b/src/cairo-xcb-surface.c
+@@ -1578,6 +1578,10 @@ _cairo_xcb_surface_show_glyphs (void
+ int num_glyphs,
+ cairo_scaled_font_t *scaled_font);
+
++static cairo_bool_t
++_cairo_xcb_surface_is_compatible (void *surface_a,
++ void *surface_b);
++
+ /* XXX: move this to the bottom of the file, XCB and Xlib */
+
+ static const cairo_surface_backend_t cairo_xcb_surface_backend = {
+@@ -1609,7 +1613,8 @@ static const cairo_surface_backend_t cai
+ NULL, /* stroke */
+ NULL, /* fill */
+ _cairo_xcb_surface_show_glyphs,
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_xcb_surface_is_compatible
+ };
+
+ /**
+@@ -2451,3 +2456,13 @@ _cairo_xcb_surface_show_glyphs (void
+
+ return status;
+ }
++
++static cairo_bool_t
++_cairo_xcb_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_xcb_surface_t *a = (cairo_xcb_surface_t*) surface_a;
++ cairo_xcb_surface_t *b = (cairo_xcb_surface_t*) surface_b;
++
++ return (a->dpy == b->dpy);
++}
+diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
+index 6a0d3e4..9228c95 100644
+--- a/src/cairo-xlib-surface.c
++++ b/src/cairo-xlib-surface.c
+@@ -74,6 +74,10 @@ _cairo_xlib_surface_show_glyphs (void
+ int num_glyphs,
+ cairo_scaled_font_t *scaled_font);
+
++static cairo_bool_t
++_cairo_xlib_surface_is_compatible (void *surface_a,
++ void *surface_b);
++
+ /*
+ * Instead of taking two round trips for each blending request,
+ * assume that if a particular drawable fails GetImage that it will
+@@ -1783,7 +1787,8 @@ static const cairo_surface_backend_t cai
+ NULL, /* stroke */
+ NULL, /* fill */
+ _cairo_xlib_surface_show_glyphs,
+- NULL /* snapshot */
++ NULL, /* snapshot */
++ _cairo_xlib_surface_is_compatible
+ };
+
+ /**
+@@ -2913,3 +2918,13 @@ _cairo_xlib_surface_show_glyphs (void
+
+ return status;
+ }
++
++static cairo_bool_t
++_cairo_xlib_surface_is_compatible (void *surface_a,
++ void *surface_b)
++{
++ cairo_xlib_surface_t *a = (cairo_xlib_surface_t*) surface_a;
++ cairo_xlib_surface_t *b = (cairo_xlib_surface_t*) surface_b;
++
++ return (a->dpy == b->dpy);
++}
+diff --git a/src/cairo.c b/src/cairo.c
+diff --git a/src/cairoint.h b/src/cairoint.h
+index 060b988..01c0e2a 100755
+--- a/src/cairoint.h
++++ b/src/cairoint.h
+@@ -933,6 +933,10 @@ struct _cairo_surface_backend {
+
+ cairo_surface_t *
+ (*snapshot) (void *surface);
++
++ cairo_bool_t
++ (*is_compatible) (void *surface_a,
++ void *surface_b);
+ };
+
+ typedef struct _cairo_format_masks {
+@@ -1497,6 +1501,10 @@ _cairo_color_get_rgba_premultiplied (cai
+ double *blue,
+ double *alpha);
+
++cairo_private cairo_bool_t
++_cairo_color_equal (cairo_color_t *color_a,
++ cairo_color_t *color_b);
++
+ /* cairo-font.c */
+
+ cairo_private void
+@@ -1922,6 +1930,10 @@ _cairo_surface_clone_similar (cairo_surf
+ cairo_private cairo_surface_t *
+ _cairo_surface_snapshot (cairo_surface_t *surface);
+
++cairo_private cairo_bool_t
++_cairo_surface_is_compatible (cairo_surface_t *surface_a,
++ cairo_surface_t *surface_b);
++
+ cairo_private unsigned int
+ _cairo_surface_get_current_clip_serial (cairo_surface_t *surface);
+
diff --git a/recipes/cairo/files/cairo_directfb_is_similar-typo.patch b/recipes/cairo/files/cairo_directfb_is_similar-typo.patch
new file mode 100644
index 0000000000..10c81464f0
--- /dev/null
+++ b/recipes/cairo/files/cairo_directfb_is_similar-typo.patch
@@ -0,0 +1,11 @@
+--- cairo-1.4.8/src/cairo-directfb-surface.c~org 2007-09-22 19:34:35.000000000 -0400
++++ cairo-1.4.8/src/cairo-directfb-surface.c 2007-09-22 19:36:01.000000000 -0400
+@@ -1572,7 +1572,7 @@
+ NULL, /* show_glyphs */
+ #endif
+ NULL, /* snapshot */
+- _cairo_directfb_is_similar,
++ _cairo_directfb_surface_is_similar,
+ NULL /* reset */
+ };
+
diff --git a/recipes/cairo/libsvg-0.1.4/configure_fix.patch b/recipes/cairo/libsvg-0.1.4/configure_fix.patch
new file mode 100644
index 0000000000..db20d5f05a
--- /dev/null
+++ b/recipes/cairo/libsvg-0.1.4/configure_fix.patch
@@ -0,0 +1,22 @@
+diff -urN libsvg-0.1.4.orig/configure.in libsvg-0.1.4/configure.in
+--- libsvg-0.1.4.orig/configure.in 2005-06-15 22:27:49.000000000 +0200
++++ libsvg-0.1.4/configure.in 2008-06-07 03:06:30.000000000 +0200
+@@ -9,15 +9,18 @@
+
+ # Increment if the interface has additions, changes, removals.
+ LT_CURRENT=1
++AC_SUBST(LT_CURRENT)
+
+ # Increment any time the source changes; set to
+ # 0 if you increment CURRENT
+ LT_REVISION=0
++AC_SUBST(LT_REVISION)
+
+ # Increment if any interfaces have been added; set to 0
+ # if any interfaces have been removed. removal has
+ # precedence over adding, so set to 0 if both happened.
+ LT_AGE=0
++AC_SUBST(LT_AGE)
+
+ VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE"
+ AC_SUBST(VERSION_INFO)
diff --git a/recipes/cairo/libsvg-0.1.4/gcc4_and_expat.patch b/recipes/cairo/libsvg-0.1.4/gcc4_and_expat.patch
new file mode 100644
index 0000000000..feec4ab74d
--- /dev/null
+++ b/recipes/cairo/libsvg-0.1.4/gcc4_and_expat.patch
@@ -0,0 +1,19 @@
+diff -bur libsvg-0.1.4~orig/src/svg_parser_expat.c libsvg-0.1.4/src/svg_parser_expat.c
+--- libsvg-0.1.4~orig/src/svg_parser_expat.c 2005-02-14 11:26:26.000000000 -0600
++++ libsvg-0.1.4/src/svg_parser_expat.c 2006-02-10 21:58:20.000000000 -0600
+@@ -30,6 +30,7 @@
+ #include "svgint.h"
+ #include "svg_hash.h"
+
++#ifndef LIBSVG_EXPAT
+ static void
+ _svg_parser_sax_start_element (void *closure,
+ const XML_Char *name,
+@@ -43,6 +44,7 @@
+ _svg_parser_sax_characters (void *closure,
+ const XML_Char *ch,
+ int len);
++#endif
+
+ static void
+ _svg_parser_sax_warning (void *closure,
diff --git a/recipes/cairo/libsvg-cairo/libsvg-cairo-libtool.diff b/recipes/cairo/libsvg-cairo/libsvg-cairo-libtool.diff
new file mode 100644
index 0000000000..90448dc887
--- /dev/null
+++ b/recipes/cairo/libsvg-cairo/libsvg-cairo-libtool.diff
@@ -0,0 +1,27 @@
+Index: libsvg-cairo/configure.in
+===================================================================
+--- libsvg-cairo.orig/configure.in 2008-11-04 13:38:51.795236755 +0300
++++ libsvg-cairo/configure.in 2008-11-04 13:40:44.503218844 +0300
+@@ -8,18 +8,18 @@ LIBSVG_CAIRO_VERSION=0.1.5-head
+ # libtool shared library version
+
+ # Increment if the interface has additions, changes, removals.
+-LT_CURRENT=1
++LV_CURRENT=1
+
+ # Increment any time the source changes; set to
+ # 0 if you increment CURRENT
+-LT_REVISION=1
++LV_REVISION=1
+
+ # Increment if any interfaces have been added; set to 0
+ # if any interfaces have been removed. removal has
+ # precedence over adding, so set to 0 if both happened.
+-LT_AGE=0
++LV_AGE=0
+
+-VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE"
++VERSION_INFO="$LV_CURRENT:$LV_REVISION:$LV_AGE"
+ AC_SUBST(VERSION_INFO)
+
+ dnl ===========================================================================
diff --git a/recipes/cairo/libsvg-cairo_0.1.5.bb b/recipes/cairo/libsvg-cairo_0.1.5.bb
new file mode 100644
index 0000000000..add660752a
--- /dev/null
+++ b/recipes/cairo/libsvg-cairo_0.1.5.bb
@@ -0,0 +1,13 @@
+SECTION = "libs"
+LICENSE = "LGPL"
+PRIORITY = "optional"
+DEPENDS = "libsvg cairo"
+DESCRIPTION = "SVG rendering library"
+
+SRC_URI = "http://cairographics.org/snapshots/libsvg-cairo-${PV}.tar.gz"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/libsvg-cairo_0.1.6.bb b/recipes/cairo/libsvg-cairo_0.1.6.bb
new file mode 100644
index 0000000000..add660752a
--- /dev/null
+++ b/recipes/cairo/libsvg-cairo_0.1.6.bb
@@ -0,0 +1,13 @@
+SECTION = "libs"
+LICENSE = "LGPL"
+PRIORITY = "optional"
+DEPENDS = "libsvg cairo"
+DESCRIPTION = "SVG rendering library"
+
+SRC_URI = "http://cairographics.org/snapshots/libsvg-cairo-${PV}.tar.gz"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/libsvg-cairo_20050601.bb b/recipes/cairo/libsvg-cairo_20050601.bb
new file mode 100644
index 0000000000..9cc7c5b46c
--- /dev/null
+++ b/recipes/cairo/libsvg-cairo_20050601.bb
@@ -0,0 +1,18 @@
+PV = "0.0+cvs${FIXEDSRCDATE}"
+FIXEDSRCDATE = "${@bb.data.getVar('FILE', d, 1).split('_')[-1].split('.')[0]}"
+
+SECTION = "libs"
+LICENSE = "LGPL"
+PRIORITY = "optional"
+DEPENDS = "libsvg cairo"
+DESCRIPTION = "SVG rendering library"
+DEFAULT_PREFERENCE = "1"
+SRC_URI = "cvs://anoncvs:anoncvs@cvs.cairographics.org/cvs/cairo;module=libsvg-cairo;date=${FIXEDSRCDATE} \
+ file://libsvg-cairo-libtool.diff;patch=1"
+S = "${WORKDIR}/libsvg-cairo"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/libsvg-cairo_cvs.bb b/recipes/cairo/libsvg-cairo_cvs.bb
new file mode 100644
index 0000000000..6f9111e31b
--- /dev/null
+++ b/recipes/cairo/libsvg-cairo_cvs.bb
@@ -0,0 +1,15 @@
+PV = "0.0+cvs${SRCDATE}"
+SECTION = "libs"
+LICENSE = "LGPL"
+PRIORITY = "optional"
+DEPENDS = "libsvg cairo"
+DESCRIPTION = "SVG rendering library"
+DEFAULT_PREFERENCE = "-1"
+SRC_URI = "cvs://anoncvs:anoncvs@cvs.cairographics.org/cvs/cairo;module=libsvg-cairo"
+S = "${WORKDIR}/libsvg-cairo"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/libsvg_0.1.4.bb b/recipes/cairo/libsvg_0.1.4.bb
new file mode 100644
index 0000000000..2c5578aea6
--- /dev/null
+++ b/recipes/cairo/libsvg_0.1.4.bb
@@ -0,0 +1,18 @@
+SECTION = "libs"
+LICENSE = "LGPL"
+PRIORITY = "optional"
+DEPENDS = "expat jpeg zlib libpng"
+DESCRIPTION = "SVG parser library"
+PR = "r1"
+
+SRC_URI = "http://cairographics.org/snapshots/libsvg-${PV}.tar.gz \
+ file://configure_fix.patch;patch=1 \
+ file://gcc4_and_expat.patch;patch=1"
+
+EXTRA_OECONF = "--with-expat"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/libsvg_cvs.bb b/recipes/cairo/libsvg_cvs.bb
new file mode 100644
index 0000000000..95b360c041
--- /dev/null
+++ b/recipes/cairo/libsvg_cvs.bb
@@ -0,0 +1,17 @@
+PV = "0.0+cvs${SRCDATE}"
+SECTION = "libs"
+PRIORITY = "optional"
+DEPENDS = "expat jpeg zlib libpng"
+DESCRIPTION = "SVG parser library"
+LICENSE = "LGPL"
+SRC_URI = "cvs://anoncvs:anoncvs@cvs.cairographics.org/cvs/cairo;module=libsvg"
+S = "${WORKDIR}/libsvg"
+PR = "r2"
+
+EXTRA_OECONF = "--with-expat"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}
diff --git a/recipes/cairo/xsvg_cvs.bb b/recipes/cairo/xsvg_cvs.bb
new file mode 100644
index 0000000000..210898f576
--- /dev/null
+++ b/recipes/cairo/xsvg_cvs.bb
@@ -0,0 +1,18 @@
+PV = "0.0+cvs${SRCDATE}"
+LICENSE = "MIT-X"
+SECTION = "libs"
+PRIORITY = "optional"
+DEPENDS = "libsvg-cairo xcursor"
+DESCRIPTION = "SVG viewer"
+
+SRC_URI = "cvs://anoncvs:anoncvs@cvs.cairographics.org/cvs/cairo;module=xsvg"
+S = "${WORKDIR}/xsvg"
+
+# FIXME: add xcursor
+BROKEN = "1"
+
+inherit autotools pkgconfig
+
+do_stage () {
+ autotools_stage_all
+}