From 34a4ad1e5bca8db34933718db245a232ebe30ce2 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 2 Mar 2006 10:32:38 -0800 Subject: [PATCH] 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. --- test/.gitignore | 1 + test/Makefile.am | 2 + test/show-glyphs-many-ref.png | Bin 0 -> 118 bytes test/show-glyphs-many-rgb24-ref.png | Bin 0 -> 115 bytes test/show-glyphs-many.c | 127 ++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 test/show-glyphs-many-ref.png create mode 100644 test/show-glyphs-many-rgb24-ref.png create mode 100644 test/show-glyphs-many.c diff --git a/test/.gitignore b/test/.gitignore index 65741ca63..8a1a8acf0 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 8a67fc53e..f1fe6f512 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 = $(LDADDS) 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 0000000000000000000000000000000000000000..b61c5f7b6a7ed59306efc2dcf201a4335e4054e5 GIT binary patch literal 118 zcmeAS@N?(olHy`uVBq!ia0vp^oIuRY!3HGPMlP2IQfx`y?k)`fL2$v|<&%LT>?NMQ zuI$&CnS`XQdS-6k2NaUY)lQE6Pf~DL&8`X;$>Kb{;*4g0o5>g My85}Sb4q9e0Da*f>i_@% literal 0 HcmV?d00001 diff --git a/test/show-glyphs-many-rgb24-ref.png b/test/show-glyphs-many-rgb24-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..450e8e0bb5eb180b7c5e83e16782a552a9bf0e7d GIT binary patch literal 115 zcmeAS@N?(olHy`uVBq!ia0vp^oIuRY!2~3gtPOmC6kC$Fy9>jA5L~c#`DCC7dx@v7 zEBiHOCLt-So|&8X0fj_8T^vIsrY8US|KFaO??8)pQp;&ZhK20R!oKrXg##5Zc)I$z JtaD0e0sz6V9!UTI literal 0 HcmV?d00001 diff --git a/test/show-glyphs-many.c b/test/show-glyphs-many.c new file mode 100644 index 000000000..3c444114d --- /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 + */ + +#include "cairo-test.h" + +#include + +/* Bug history + * + * 2006-01-07 Jon Hellan + * + * Jon opened the following bug report: + * + * _XError from XRenderCompositeText8 + * https://bugs.freedesktop.org/show_bug.cgi?id=5528 + * + * 2006-03-02 Carl Worth + * + * 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); +}