[cairo-commit] 2 commits - src/cairo-xlib-surface.c test/bilevel-image.c test/bilevel-image-ref.png test/.gitignore test/Makefile.am

Chris Wilson ickle at kemper.freedesktop.org
Fri Apr 4 10:12:48 PDT 2008


 src/cairo-xlib-surface.c   |   14 +++++++++
 test/.gitignore            |    1 
 test/Makefile.am           |    2 +
 test/bilevel-image-ref.png |binary
 test/bilevel-image.c       |   68 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 85 insertions(+)

New commits:
commit 2c8ead12a64d0deff4dc9e32c60f2815fe7c4a63
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Apr 4 17:46:54 2008 +0100

    [xlib] Avoiding sending glyphs > XMaxRequestSize.
    
    XRenderAddGlyph() does not split its image data across multiple requests
    and so the glyph surface must be smaller than XMaxRequestSize or else
    the server will disconnect the client, causing "Fatal IO error 104".
    As this will require an extension to the XRender spec, we can work
    around the issue by using our fallbacks if we detect that the glyph will
    be too large for a single request.
    
    See bugs https://bugs.freedesktop.org/show_bug.cgi?id=4339 and
    http://bugs.freedesktop.org/show_bug.cgi?id=13266 for examples.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index df80ca6..48b7550 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2925,6 +2925,20 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
 	already_had_glyph_surface = TRUE;
     }
 
+    /* XXX XRenderAddGlyph does not handle a glyph surface larger than the
+     * maximum XRequest size.
+     */
+    {
+	/* pessimistic length estimation in case we need to change formats */
+	int len = 4 * glyph_surface->width * glyph_surface->height;
+	int max_request_size = XMaxRequestSize (dpy)  -
+	                       sz_xRenderAddGlyphsReq -
+	                       sz_xGlyphInfo          -
+			       4;
+	if (len >= max_request_size)
+	    return CAIRO_INT_STATUS_UNSUPPORTED;
+    }
+
     if (scaled_font->surface_private == NULL) {
 	status = _cairo_xlib_surface_font_init (dpy, scaled_font);
 	if (status)
commit a4f94624b2f4a85bafbc2dc01b08788a7a88deba
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Apr 4 15:56:22 2008 +0100

    [test] Add bilevel image test case.
    
    Add a simple test to exercise the embedding of an image with a bilevel
    alpha channel into a postscript level 3 document.

diff --git a/test/.gitignore b/test/.gitignore
index 689ecf0..af0387a 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -10,6 +10,7 @@ a1-traps-sample
 a8-mask
 big-line
 big-trap
+bilevel-image
 bitmap-font
 caps-joins
 caps-joins-alpha
diff --git a/test/Makefile.am b/test/Makefile.am
index b73df23..f02a5ac 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,6 +8,7 @@ a1-traps-sample$(EXEEXT)				\
 a8-mask$(EXEEXT)					\
 big-line$(EXEEXT)					\
 big-trap$(EXEEXT)					\
+bilevel-image$(EXEEXT)					\
 caps-joins$(EXEEXT)					\
 caps-joins-alpha$(EXEEXT)				\
 caps-sub-paths$(EXEEXT)					\
@@ -267,6 +268,7 @@ REFERENCE_IMAGES = \
 	big-line-ps-rgb24-ref.png	\
 	big-line-quartz-ref.png		\
 	big-line-quartz-rgb24-ref.png	\
+	bilevel-image-ref.png		\
 	bitmap-font-pdf-argb32-ref.png	\
 	bitmap-font-ref.png	\
 	bitmap-font-rgb24-ref.png	\
diff --git a/test/bilevel-image-ref.png b/test/bilevel-image-ref.png
new file mode 100644
index 0000000..cae76d6
Binary files /dev/null and b/test/bilevel-image-ref.png differ
diff --git a/test/bilevel-image.c b/test/bilevel-image.c
new file mode 100644
index 0000000..7898a5f
--- /dev/null
+++ b/test/bilevel-image.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2008 Chris Wilson
+ *
+ * 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
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "bilevel-image",
+    "Test that PS can embed an RGB image with a bilevel alpha channel.",
+    12, 4,
+    draw
+};
+
+#define RGBx 0xffff0000, 0xff00ff00, 0xff0000ff, 0x00000000
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    static uint32_t data[] = {
+	RGBx, RGBx, RGBx,
+	RGBx, RGBx, RGBx,
+	RGBx, RGBx, RGBx,
+	RGBx, RGBx, RGBx,
+    };
+    cairo_surface_t *mask;
+
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_paint (cr);
+
+    mask = cairo_image_surface_create_for_data ((unsigned char *) data,
+						CAIRO_FORMAT_ARGB32, 12, 4, 48);
+
+    cairo_set_source_surface (cr, mask, 0, 0);
+    cairo_surface_destroy (mask);
+
+    cairo_paint (cr);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}


More information about the cairo-commit mailing list