summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2013-01-04 00:23:42 -0600
committerBehdad Esfahbod <behdad@behdad.org>2013-01-04 00:23:42 -0600
commit4ab0d57a7f7bfcd8a4b893d23f7a4923806a9113 (patch)
tree4e46c7c6ef286b19bf4affba72ed943c656ea37b
parent6978bb5c26147bea96af083c282dc95c67cfb257 (diff)
downloadpango-4ab0d57a7f7bfcd8a4b893d23f7a4923806a9113.tar.gz
Refactor test-pangocairo-threads.c
-rw-r--r--tests/test-pangocairo-threads.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/tests/test-pangocairo-threads.c b/tests/test-pangocairo-threads.c
index 400d5651..97d5dfe8 100644
--- a/tests/test-pangocairo-threads.c
+++ b/tests/test-pangocairo-threads.c
@@ -7,6 +7,29 @@ int num_iters = 100;
GMutex mutex;
+static PangoLayout *
+create_layout (cairo_t *cr)
+{
+ PangoLayout *layout = pango_cairo_create_layout (cr);
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_set_width (layout, 100 * PANGO_SCALE);
+ return layout;
+}
+
+static void
+draw (cairo_t *cr, PangoLayout *layout)
+{
+ cairo_set_source_rgba (cr, 1, 1, 1, 1);
+ cairo_paint (cr);
+ cairo_set_source_rgba (cr, 1, 1, 1, 0);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+ /* force a relayout */
+ pango_layout_context_changed (layout);
+
+ pango_cairo_show_layout (cr, layout);
+}
+
static gpointer
thread_func (gpointer data)
{
@@ -18,28 +41,13 @@ thread_func (gpointer data)
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 100, 100);
cairo_t *cr = cairo_create (surface);
+ layout = create_layout (cr);
+
g_mutex_lock (&mutex);
g_mutex_unlock (&mutex);
- layout = pango_cairo_create_layout (cr);
-
- pango_layout_set_text (layout, text, -1);
- pango_layout_set_width (layout, 100 * PANGO_SCALE);
-
for (i = 0; i < num_iters; i++)
- {
- cairo_set_source_rgba (cr, 1, 1, 1, 1);
- cairo_paint (cr);
- cairo_set_source_rgba (cr, 1, 1, 1, 0);
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-
- /* force a relayout */
- pango_layout_set_wrap (layout,
- pango_layout_get_wrap (layout) == PANGO_WRAP_WORD ?
- PANGO_WRAP_CHAR : PANGO_WRAP_WORD);
-
- pango_cairo_show_layout (cr, layout);
- }
+ draw (cr, layout);
filename = g_strdup_printf ("%d.png", num);
cairo_surface_write_to_png (surface, filename);