[cairo-commit] 3 commits - src/cairo-xlib-surface.c test/.gitignore
test/Makefile.am test/show-glyphs-many.c
test/show-glyphs-many-ref.png test/show-glyphs-many-rgb24-ref.png
Carl Worth
cworth at kemper.freedesktop.org
Fri Mar 3 15:43:29 PST 2006
src/cairo-xlib-surface.c | 49 +++++++++----
test/.gitignore | 1
test/Makefile.am | 2
test/show-glyphs-many-ref.png |binary
test/show-glyphs-many-rgb24-ref.png |binary
test/show-glyphs-many.c | 127 ++++++++++++++++++++++++++++++++++++
6 files changed, 165 insertions(+), 14 deletions(-)
New commits:
diff-tree 3333bba82d26a0b11961af3cb5c29c79a1a0d07b (from parents)
Merge: 62812b25c7f0c11aa6c973b722fa8e1bd088d4b8 3370cd631858cac0fd3ce33c74db3af40991e6f1
Author: Carl Worth <cworth at cworth.org>
Date: Fri Mar 3 15:41:14 2006 -0800
Merge branch 'show-glyphs-many' into cairo
diff-tree 3370cd631858cac0fd3ce33c74db3af40991e6f1 (from 34a4ad1e5bca8db34933718db245a232ebe30ce2)
Author: Carl Worth <cworth at cworth.org>
Date: Fri Mar 3 15:40:58 2006 -0800
_cairo_xlib_surface_old_show_glyphs: Break up rendering into chunks to fit
into X max request length protocol limits.
This fixes bug #5528:
_XError from XRenderCompositeText8
https://bugs.freedesktop.org/show_bug.cgi?id=5528
(cherry picked from 7d498ca91279a4e793d704c5b878f070be4c878f commit)
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index a62afed..6def998 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -41,6 +41,7 @@
#include "cairo-xlib-test.h"
#include "cairo-xlib-private.h"
#include <X11/extensions/Xrender.h>
+#include <X11/extensions/renderproto.h>
/* Xlib doesn't define a typedef, so define one ourselves */
typedef int (*cairo_xlib_error_func_t) (Display *display,
@@ -2404,6 +2405,8 @@ _cairo_xlib_surface_old_show_glyphs (cai
cairo_int_status_t status;
cairo_xlib_surface_t *self = abstract_surface;
cairo_xlib_surface_t *src;
+ const cairo_glyph_t *glyphs_chunk;
+ int glyphs_remaining, chunk_size, max_chunk_size;
composite_operation_t operation;
cairo_scaled_glyph_t *scaled_glyph;
cairo_xlib_surface_font_private_t *font_private;
@@ -2458,23 +2461,41 @@ _cairo_xlib_surface_old_show_glyphs (cai
}
_cairo_xlib_surface_ensure_dst_picture (self);
- /* Call the appropriate sub-function. */
+ max_chunk_size = XMaxRequestSize (self->dpy);
if (max_index < 256)
- status = _cairo_xlib_surface_old_show_glyphs8 (scaled_font, op, src, self,
- source_x + attributes.x_offset - dest_x,
- source_y + attributes.y_offset - dest_y,
- glyphs, num_glyphs);
+ max_chunk_size -= sz_xRenderCompositeGlyphs8Req;
else if (max_index < 65536)
- status = _cairo_xlib_surface_old_show_glyphs16 (scaled_font, op, src, self,
- source_x + attributes.x_offset - dest_x,
- source_y + attributes.y_offset - dest_y,
- glyphs, num_glyphs);
- else
- status = _cairo_xlib_surface_old_show_glyphs32 (scaled_font, op, src, self,
- source_x + attributes.x_offset - dest_x,
- source_y + attributes.y_offset - dest_y,
- glyphs, num_glyphs);
+ max_chunk_size -= sz_xRenderCompositeGlyphs16Req;
+ else
+ max_chunk_size -= sz_xRenderCompositeGlyphs32Req;
+ max_chunk_size /= sz_xGlyphElt;
+
+ for (glyphs_remaining = num_glyphs, glyphs_chunk = glyphs;
+ glyphs_remaining;
+ glyphs_remaining -= chunk_size, glyphs_chunk += chunk_size)
+ {
+ chunk_size = MIN (glyphs_remaining, max_chunk_size);
+
+ /* Call the appropriate sub-function. */
+ if (max_index < 256)
+ status = _cairo_xlib_surface_old_show_glyphs8 (scaled_font, op, src, self,
+ source_x + attributes.x_offset - dest_x,
+ source_y + attributes.y_offset - dest_y,
+ glyphs_chunk, chunk_size);
+ else if (max_index < 65536)
+ status = _cairo_xlib_surface_old_show_glyphs16 (scaled_font, op, src, self,
+ source_x + attributes.x_offset - dest_x,
+ source_y + attributes.y_offset - dest_y,
+ glyphs_chunk, chunk_size);
+ else
+ status = _cairo_xlib_surface_old_show_glyphs32 (scaled_font, op, src, self,
+ source_x + attributes.x_offset - dest_x,
+ source_y + attributes.y_offset - dest_y,
+ glyphs_chunk, chunk_size);
+ if (status != CAIRO_STATUS_SUCCESS)
+ break;
+ }
if (status == CAIRO_STATUS_SUCCESS && !_cairo_operator_bounded_by_mask (op)) {
cairo_rectangle_t extents;
diff-tree 34a4ad1e5bca8db34933718db245a232ebe30ce2 (from 3490ed989672eaf2c08468ba81e3376fa362e41f)
Author: Carl Worth <cworth at cworth.org>
Date: Thu Mar 2 10:32:38 2006 -0800
test/show-glyphs-many: New test case to demonstrate bug #5528
This demonstrates an Xlib crash when rendering many glyphs. See:
_XError from XRenderCompositeText8
https://bugs.freedesktop.org/show_bug.cgi?id=5528
for more details.
diff --git a/test/.gitignore b/test/.gitignore
index 65741ca..8a1a8ac 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -61,6 +61,7 @@ select-font-no-show-text
self-copy
self-intersecting
set-source
+show-glyphs-many
show-text-current-point
source-clip
source-surface-scale-paint
diff --git a/test/Makefile.am b/test/Makefile.am
index 8a67fc5..f1fe6f5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -44,6 +44,7 @@ select-font-no-show-text \
self-copy \
self-intersecting \
set-source \
+show-glyphs-many \
show-text-current-point \
source-clip \
source-surface-scale-paint \
@@ -331,6 +332,7 @@ select_font_no_show_text_LDADD = $(LDADD
self_copy_LDADD = $(LDADDS)
self_intersecting_LDADD = $(LDADDS)
set_source_LDADD = $(LDADDS)
+show_glyphs_many_LDADD = $(LDADDS)
show_text_current_point_LDADD = $(LDADDS)
source_clip_LDADD = $(LDADDS)
source_surface_scale_paint_LDADD = $(LDADDS)
diff --git a/test/show-glyphs-many-ref.png b/test/show-glyphs-many-ref.png
new file mode 100644
index 0000000..b61c5f7
Binary files /dev/null and b/test/show-glyphs-many-ref.png differ
diff --git a/test/show-glyphs-many-rgb24-ref.png b/test/show-glyphs-many-rgb24-ref.png
new file mode 100644
index 0000000..450e8e0
Binary files /dev/null and b/test/show-glyphs-many-rgb24-ref.png differ
diff --git a/test/show-glyphs-many.c b/test/show-glyphs-many.c
new file mode 100644
index 0000000..3c44411
--- /dev/null
+++ b/test/show-glyphs-many.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2006 Red Hat, Inc.
+ *
+ * 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
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#include <string.h>
+
+/* Bug history
+ *
+ * 2006-01-07 Jon Hellan <hellan at acm.org>
+ *
+ * Jon opened the following bug report:
+ *
+ * _XError from XRenderCompositeText8
+ * https://bugs.freedesktop.org/show_bug.cgi?id=5528
+ *
+ * 2006-03-02 Carl Worth <cworth at cworth.org>
+ *
+ * I wrote this test case to demonstrate the bug.
+ *
+ * Approach:
+ *
+ * Draw 65535 glyphs white-on-white all on top of each other.
+ *
+ * Rationale:
+ *
+ * The number 65535 comes from the original bug report.
+ *
+ * I would use cairo_show_text with a long string of 'x's say,
+ * but then the surface would need to be enormous to contain
+ * them. A smaller surface could be used, but I fear that at some
+ * point the off-surface glyph drawing would be optimized away
+ * and not exercise the bug.
+ *
+ * So, to keep the surface size under control, I use
+ * cairo_show_glyphs which allows me to place the glyphs all on
+ * top of each other. But, since cairo doesn't provide any
+ * character-to-glyphs mapping, I can't get a reliable glyph
+ * index (for character 'x' for example). So I just "guess" a
+ * glyph index and use white-on-white drawing to ignore the
+ * result. (I don't care what's drawn---I just want to ensure
+ * that things don't crash.)
+ *
+ * Status: I replicated bug. The largest value of NUM_GLYPHS for
+ * which I saw success is 21842.
+ */
+
+#define TEXT_SIZE 12
+#define NUM_GLYPHS 65535
+
+/* This is the index into the font for what glyph we'll draw. Since we
+ * don't guarantee we'll get any particular font, we can't relibably
+ * get any particular glyph. But we don't care what we draw anyway,
+ * (see discussion of white-on-white drawing above). For what it's
+ * worth, this appears to be giving me 'M' with Bitstream Vera
+ * Sans Mono. */
+#define GLYPH_INDEX 48
+
+cairo_test_t test = {
+ "show-glyphs-many",
+ "Test that cairo_show_glyps works when handed 'many' glyphs",
+ 9, 11
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ cairo_glyph_t glyphs[NUM_GLYPHS];
+ cairo_font_options_t *font_options;
+ int i;
+
+ /* Initialize our giant array of glyphs. */
+ for (i=0; i < NUM_GLYPHS; i++) {
+ glyphs[i].index = GLYPH_INDEX;
+ glyphs[i].x = 1.0;
+ glyphs[i].y = height - 1;
+ }
+
+ /* Paint white background. */
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+ cairo_paint (cr);
+
+ cairo_select_font_face (cr, "Bitstream Vera Sans Mono",
+ CAIRO_FONT_SLANT_NORMAL,
+ CAIRO_FONT_WEIGHT_NORMAL);
+ cairo_set_font_size (cr, TEXT_SIZE);
+
+ font_options = cairo_font_options_create ();
+
+ cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
+ cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY);
+
+ cairo_set_font_options (cr, font_options);
+ cairo_font_options_destroy (font_options);
+
+ cairo_show_glyphs (cr, glyphs, NUM_GLYPHS);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+ return cairo_test (&test, draw);
+}
More information about the cairo-commit
mailing list